关于网友提出的“ python 爬虫问题,请问为什么我爬不下这个的数据?求解,网站都能打开。”问题疑问,本网通过在网上对“ python 爬虫问题,请问为什么我爬不下这个的数据?求解,网站都能打开。”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: python 爬虫问题,请问为什么我爬不下这个的数据?求解,网站都能打开。
描述:import sys
import time
import requests
import json
reload(sys)
sys.setdefaultencoding('utf-8')
time=int(time.time())
session=requests.session()
user_agent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36'
headers={'User-Agent':user_agent,'Host':'xygs.gsaic.gov.cn','Connection':'keep-alive','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'}
params={'pripid':'62030200052016012700011'}
cookies={'JSESSIONID':'2B33BC6D34DF44BE8D76C2AE20701D95'}
Url='http://xygs.gsaic.gov.cn/gsxygs/smallEnt!view.do?pripid=62030200052016012700011'
captcha=session.get(Url,headers=headers,params=(params),cookies=cookies).text
print captcha
得不到表格里的信息,求解为什么啊?
解决方案1:网页表格使用了ajax技术。你可以用chrome工具中的Network看表格来源。
另外爬虫不仅语言python基础。你最好学习下web开发相关的知识,特别是js和http协议
不好意思,之前因为在手机上作答所以没有仔细看、
刚刚看了下,是因为你缺少Accept-Language协议头
解决方案2:https://segmentfault.com/q/1010000005117988
前一个问题帮你解答了,不知道有没有解决你的问题,为啥没有任何反映
如已解决记得采纳, 这个问题的代码如下:
import requests
headers = {
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6'
}
url = 'http://xygs.gsaic.gov.cn/gsxygs/smallEnt!view.do?pripid=62030200052016012700011'
r = requests.get(url, headers=headers)
print r.text
以上介绍了“ python 爬虫问题,请问为什么我爬不下这个的数据?求解,网站都能打开。”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2175930.html