网页源代码抓取工具(网页源代码抓取工具+beautifulsoup=解决多个浏览器访问host不一致)
优采云 发布时间: 2022-03-09 03:02网页源代码抓取工具(网页源代码抓取工具+beautifulsoup=解决多个浏览器访问host不一致)
网页源代码抓取工具requests+beautifulsoup==解决多个浏览器访问host不一致,浏览器同时开多个网页,相互post一致内容,操作属性值问题,
importrequestsimportbs4frombs4importbeautifulsoupurl='={}'headers={'user-agent':'mozilla/5.0(windowsnt6.1;win64;x6
4)applewebkit/537。36(khtml,likegecko)chrome/57。3004。126safari/537。36'}#请求头yieldrequests。get(url=url,headers=headers)url_text=yieldstr(url_text)#样式表plt。
rcparams['font。sans-serif']=['simhei']#返回内容body=requests。post(url_text,{'user-agent':'mozilla/5。0(windowsnt6。1;win64;x6。
4)applewebkit/537。36(khtml,likegecko)chrome/57。3004。126safari/537。36'},headers=headers)print(body)#解析(可以通过json格式下读取body内容)print(re。findall('*',body))print(body。slice(2,。
2))#返回结果