《Python数据分析实践Python数据分析实践 (6).pdf》由会员分享,可在线阅读,更多相关《Python数据分析实践Python数据分析实践 (6).pdf(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、2021/11/20 下午10:462.3.3file:/C:/Users/sgl/Downloads/2.3.3.html1/2In:import requests-发送请求,查看响应各个属性In:url=http:/ r=requests.get(url)In:r.status_code In:r.url In:r.headers In:r.request In:r.content In:r.encoding In:r.apparent_encoding In:r.encoding=r.apparent_encoding In:def getHtml(url):try:r=requests
2、.get(url)r.raise_for_status()r.encoding=r.apparent_encoding except:print(error)return r.text 2021/11/20 下午10:462.3.3file:/C:/Users/sgl/Downloads/2.3.3.html2/2In:html=getHtml(url)print(html)In:html=getHtml(url)print(html)-模拟浏览器和定制请求In:import requests In:url=http:/ r=requests.get(url)In:r.text In:r.request.headers In:header=User-Agent:Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/92.0.4515.131 Safari/537.36 In:r=requests.get(url,headers=header)r.text In: