![](/img/trans.png)
[英]Is Java or Python better for writing a web-page-source-checking web service on Google App Engines?
[英]In Google App Engines, how to display the HTML source of a page of a fetched URL in Python?
在Google App Engine上,我發現此代碼正在獲取網頁的URL:
from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
這是實現該頁面HTML源代碼的正確代碼嗎? 結果變量是否包含http://www.google.com/的 HTML代碼? 如果是,為了顯示該HTML源代碼,我應該在此處使用什么Python命令而不是doSomethingWithResult(result.content) ? 打印結果似乎不是正確的方法。
是的, result.content
將包含該頁面的原始內容。 您應該檢查Content-Type
標頭,並驗證它是text/html
還是application/xhtml+xml
。
要將頁面的內容寫到響應中,請首先輸入您的狀態和標題,然后:
self.response.out.write(result.content)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.