python爬虫之js链接跳转抓取_爬虫抓取网页,返回的页面是,请打开浏览器的javascript,然后刷新浏览器。 这个怎么解决。想要跳过这个,抓取网站...
如果你要爬取的数据不是经过 js 执行产生的,可以用以下的方式import requestssession = requests.Session()headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0","Connection":"clo
如果你要爬取的数据不是经过 js 执行产生的,可以用以下的方式
import requests
session = requests.Session()
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0","Connection":"close","Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Upgrade-Insecure-Requests":"1"}
cookies = {"safedog-flow-item":"A7C62592B3B3C821E8940811D417910B","__utmz":"63149887.1503977571.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)","ctrl_time":"1","Hm_lvt_8f396c620ee16c3d331cf84fd54feafe":"1503977516","__utmt":"1","__cfduid":"d61cc443d7df1327ad4ee0c17da83adcf1503977565","Hm_lpvt_8f396c620ee16c3d331cf84fd54feafe":"1503977628","cf_clearance":"6c62a4b3214679cbbf0e76f7feb17fcbe1e9955a-1503977569-31536000","agronetCookie":"D98233C159EF3AEA333D883B971C1FCA9B6F08A7476FD809","__utmb":"63149887.2.10.1503977571","bdshare_firstime":"1503977570334","__utmc":"63149887","yjs_id":"Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010.12%3B%20rv%3A52.0)%20Gecko%2F20100101%20Firefox%2F52.0%7Cwww.agronet.com.cn%7C1503977570020%7Chttp%3A%2F%2Fwww.agronet.com.cn%2F","__utma":"63149887.720670875.1503977571.1503977571.1503977571.1"}
response = session.get("http://www.agronet.com.cn/", headers=headers, cookies=cookies)
print("Status code: %i" % response.status_code)
print("Response body: %s" % response.content)
如果是 js 产生的数据,建议用 webdriver
更多推荐
所有评论(0)