当我使用requests.get获取某些网站时,它不会返回完整的结果。标题。 我的代码:
import requests
url="http://114.54.23.46"
res=requests.get(url)
print res.content
结果:
'\n\n<!doctype html>\n<meta name="description" content="\xe5\xb0\x8f\xe7\xb1\xb3\xe5\xb8\x90\xe5\x8f\xb7\xe8\x83\xbd\xe4\xbd\xbf\xe7\x94\xa8\xe5\xb0\x8f\xe7\xb1\xb3\xe6\x89\x8b\xe6\x9c\xba\xef\xbc\x8cMIUI\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe4\xba\x91\xef\xbc\x8c\xe5\xa4\x9a\xe7\x9c\x8b\xe9\x98\x85\xe8\xaf\xbb\xef\xbc\x8c\xe7\xb1\xb3\xe8\x81\x8a\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe7\xa4\xbe\xe5\x8c\xba\xe7\xad\x89\xe5\xb0\x8f\xe7\xb1\xb3\xe6\x9c\x8d\xe5\x8a\xa1\xe3\x80\x82" />\n<meta name="keywords" content="\xe5\xb0\x8f\xe7\xb1\xb3\xe5\xb8\x90\xe5\x8f\xb7\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe8\xb4\xa6\xe5\x8f\xb7\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe6\xb3\xa8\xe5\x86\x8c\xef\xbc\x8c\xe6\xb3\xa8\xe5\x86\x8c\xef\xbc\x8cMi Account\xef\xbc\x8cSign in\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xef\xbc\x8c\xe5\xb8\x90\xe5\x8f\xb7\xef\xbc\x8c\xe8\xb4\xa6\xe5\x8f\xb7\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe5\xb8\x90\xe6\x88\xb7\xef\xbc\x8c\xe7\x99\xbb\xe5\xbd\x95\xef\xbc\x8c\xe7\x99\xbb\xe9\x99\x86\xef\xbc\x8c\xe5\xae\x89\xe5\x85\xa8\xe4\xbb\xa4\xe7\x89\x8c\xef\xbc\x8c\xe5\x8a\xa8\xe6\x80\x81\xe5\x8f\xa3\xe4\xbb\xa4\xef\xbc\x8c\xe5\xb0\x8f\xe7\xb1\xb3\xe6\xb3\xa8\xe5\x86\x8c\xef\xbc\x8c\xe6\x89\xbe\xe5\x9b\x9e\xe5\xaf\x86\xe7\xa0\x81" />\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n\n \n \n \n \n \n \n \n \n \n \n\n \n\n
<script>\nvar LANG=(function(){\n var locale=("zh_CN").toLowerCase();\n if(locale){\n if(locale.indexOf("en")>-1){\n return {data:"en",cls:"en"};\n }else if(locale.indexOf("zh")>-1){\n if(locale.indexOf("cn")===-1){\n return {data:"tw",cls:"zh_TW"};\n }else{\n return {data:"cn",cls:"zh_CN"};\n }\n }\n }\n return {data:"en",cls:"en"};\n})();\n</script>\n\n
<script>\nvar _d_={};\nvar _t_={\n statURL:\'https://data.mistat.xiaomi.com/mistats\',\n appId:"2882303761517246742",\n appKey:"5621724658742",\n jspcomplete:(new Date()).getTime(),\n supportLocalstorage:!!window.localStorage,\n samplingBase:100,\n samplingRate:5\n};\nif(window.performance){\n var timing=performance.timing;\n if(!timing.responseEnd){\n timing.responseEnd=timing.responseStart;\n }\n _d_.startTS=timing.fetchStart\n _d_.endTS=timing.responseEnd;\n}else{\n _d_.startTS=_d_.endTS=(new Date()).getTime();\n}\nvar JSP_VAR={\n deviceType:\'PC\',\n dataCenter:\'hh\',\n locale:"zh_CN",\n region:"CN",\n callback:"http://vip.miliao.com/sts?sign=OX%2BrnFCklhTx9DnnvktkM%2F7lESo%3D&followup=http%3A%2F%2F114.54.23.46%2F",\n sid:"vip.miliao.com",\n qs:"%3Fcallback%3Dhttp%253A%252F%252Fvip.miliao.com%252Fsts%253Fsign%253DOX%25252BrnFCklhTx9DnnvktkM%25252F7lESo%25253D%2526followup%253Dhttp%25253A%25252F%25252F114.54.23.46%25252F%26sid%3Dvip.miliao.com",\n hidden:"",\n "_sign":"2im3EnAZlcYBLXzg7BUeCCx0ulU=",\n serviceParam :\'{"checkSafePhone":false}\',\n
privacyLink:\'http://www.miui.com/res/doc/privacy/cn.html\'\n};\nvar PAGE_VAR={\n form_cache:false,\n cache_key:(JSP_VAR.deviceType!=="mobile" ? "/static/res/1a91f87/account-static/html/login/dist/v2/login-cn.html" : "/static/res/1a91f87/account-static/html/login/dist/v2/login-wap-cn.html")\n};\nif(location.search.indexOf("_debugMode")>-1){\n window.localStorage && window.localStorage.removeItem(PAGE_VAR.cache_key);\n}\n(function(){\n function getLocal(url){\n if(window.localStorage){\n var data=localStorage.getItem(url);\n return data;\n }\n return null;\n }\n function setLocal(url,data){\n if(window.localStorage && data){\n try{\n localStorage.setItem(url,data);\n }catch(e){}\n }\n }\n function getContent(url){\n var xhr= new (window.XMLHttpRequest || window.ActiveXObject)("Microsoft.XMLHTTP");\n xhr.onreadystatechange = function() {\n
if (xhr.readyState == 4 && xhr.status == 200) {\n setLocal(url,xhr.responseText);\n _t_.htmlGetEnd=(new Date()).getTime();\n document.write(xhr.responseText);\n document.close();\n }\n };\n xhr.open("GET",url,false);\n xhr.send();\n }\n var cache_key=PAGE_VAR.cache_key;\n _t_.version=cache_key;\n var html=getLocal(cache_key);\n if(html){\n _t_.htmlCache=true;\n PAGE_VAR.form_cache=true;\n document.write(html);\n document.close();\n }else{\n _t_.htmlCache=false;\n _t_.htmlGetStart=(new Date()).getTime();\n getContent(cache_key);\n }\n})();\n</script>\n'
但是当我使用浏览器访问该网站时,源代码比结果长得多。 为什么以及如何解决这个问题呢?谢谢!