本人小白用爬虫爬取辽宁省政府招标信息的代码如下:
import requests
import datetime
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
head={
"User-Agent":agent,
}
url = "http://www.ccgp-liaoning.gov.cn/portalindex.do"
params = {
"method": "getPubInfoList",
"t_k": None,
}
data = {
"current": 1,
"rowCount": 10,
"searchPhrase": None,
"district": None,
"releaseDateStart": (datetime.datetime.now() + datetime.timedelta(days=-60)).strftime('%Y-%m-%d'),
"releaseDateEnd": datetime.datetime.now().strftime('%Y-%m-%d'),
"infoTypeCode": 1001,
"year": None,
"title": "柴油",
"privateOrCity": 1,
}
try:
response = requests.post(url, params=params, data=data, headers=head, timeout=10)
print(response.text)
返回结果为,rows中没有数据
{"current":1,"rowCount":10,"rows":[],"total":0}
用postman模拟相同参数请返回有数据
尝试过headers中加入Cookie,然而并没有用