import requests
from lxml import etree
import time
import pymysql
import json
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
'Content-Type':'application/x-www-form-urlencoded',
'Pragma':'no-cache',
'Upgrade-Insecure-Requests':'1',
'Content-Length':'86',
'Host':'www.bjda.gov.cn'
}
headers_xiangqing={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
'Pragma':'no-cache',
'Upgrade-Insecure-Requests':'1',
'Host':'www.bjda.gov.cn'
}
dd={
'pageSize':'20'
}
temp=[]
dd['currentPage'] = '10'
print(dd)
response = requests.post('http://www.bjda.gov.cn/eportal/ui?pageId=348736', headers=headers, data=dd)
selector = etree.HTML(response.text)
item_spider = list(set(selector.xpath('//tr[@class="chaxun_con"]//a/@href')))
temp.extend(item_spider)
for i in temp:
print('http://www.bjda.gov.cn/eportal/ui?pageId=348738&'+i[1:])
response=requests.get('http://www.bjda.gov.cn/eportal/ui?pageId=348738&'+i[1:],headers=headers_xiangqing)
print(response.status_code)
selector=etree.HTML(response.text)
tr=selector.xpath('//table[@class="table_sjcx"]//tr')
print(tr
python requests 爬取数据
原创
©著作权归作者所有:来自51CTO博客作者mb61b9f9821005c的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【Python requests多页面爬取案例】
" "
json firefox 起始页 python 火狐浏览器 -
静态网页爬取-Requests
静态网页爬取-Requestsimport requestsr=requests.get('://www.baidu.c
python 爬虫 .net firefox 请求头