|
50鱼币
import requests
import json
name=input("请输入关键词:")
a=input("请输入搜索开始日期,如2022-10-10:")
startTime=a+' 00:00:00'
b=input("请输入搜索开始日期,如2022-12-10:")
endTime=b+' 23:59:59'
print("正在为您搜索请稍后...")
url='https://www.cqggzy.com/interface/rest/esinteligentsearch/getFullTextDataNew'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61'}
data={
"token": "",
"pn": "0",
"rn": "999",
"sdt": "",
"edt": "",
"wd": "",
"inc_wd": "",
"exc_wd": "",
"fields": "",
"cnum": "001",
"sort": "{\"istop\":\"0\",\"ordernum\":\"0\",\"webdate\":\"0\",\"rowid\":\"0\"}",
"ssort": "",
"cl": "10000",
"terminal": "",
"condition": [
{
"fieldName": "categorynum",
"equal": "004",
"notEqual": "null",
"equalList": "null",
"notEqualList": [
"014001018",
"004002005",
"014001015",
"014005014",
"014008011"
],
"isLike": "true",
"likeType": "2"
},
{
"fieldName": "titlenew",
"equal": name,
"notEqual": "null",
"equalList": "null",
"notEqualList": "null",
"isLike": "true",
"likeType": "0"
}
],
"time": [
{
"fieldName": "webdate",
"startTime": startTime,
"endTime": endTime
}
],
"highlights": "",
"statistics": "null",
"unionCondition": [],
"accuracy": "",
"noParticiple": "1",
"searchRange": "null",
"noWd": "true"
}
response=requests.post(url=url,data=data,headers=headers)
id=response.json()
filename=startTime+'至'+endTime+'.json'
fp=open(filename,'w',encoding='utf-8')
json.dump(id,fp=fp,ensure_ascii=False)
print("over!!!")
不好意思啊,我忘了说一点,data末尾那个冒号不要加
还有,如果你的name是中文的话,直接传会报错,得在headers里面加一项,还得把data编码成utf-8
还有你的filename,里面包括冒号这种特殊字符,会报错,得把逗号替换成其他符号,我用短横杠,你也可以用其他的 import requests
import json
name = input("请输入关键词:")
a = input("请输入搜索开始日期,如2022-10-10:")
startTime = a + ' 00:00:00'
b = input("请输入搜索开始日期,如2022-12-10:")
endTime = b + ' 23:59:59'
print("正在为您搜索请稍后...")
url = 'https://www.cqggzy.com/interface/rest/esinteligentsearch/getFullTextDataNew'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61',
'Content-Type': 'text/text; charset=utf-8'
}
data = r'{"token":"","pn":0,"rn":20,"sdt":"","edt":"","wd":"","inc_wd":"","exc_wd":"","fields":"","cnum":"001","sort":"{"istop":"0","ordernum":"0","webdate":"0","rowid":"0"}","ssort":"","cl":10000,"terminal":"","condition":[{"fieldName":"categorynum","equal":"004","notEqual":null,"equalList":null,"notEqualList":["014001018","004002005","014001015","014005014","014008011"],"isLike":true,"likeType":2},{"fieldName":"titlenew","equal":"'+name+'","notEqual":null,"equalList":null,"notEqualList":null,"isLike":true,"likeType":0}],"time":[{"fieldName":"webdate","startTime":"'+startTime+'","endTime":"'+endTime+'"}],"highlights":"","statistics":null,"unionCondition":[],"accuracy":"","noParticiple":"1","searchRange":null,"noWd":true}'
response = requests.post(url=url, data=data.encode('utf-8'), headers=headers)
data_id = response.json()
filename = f"{startTime}至{endTime}.json".replace(":", "-")
fp = open(filename, 'w', encoding='utf-8')
json.dump(data_id, fp=fp, ensure_ascii=False)
print("over!!!")
|
-
最佳答案
查看完整内容
不好意思啊,我忘了说一点,data末尾那个冒号不要加
还有,如果你的name是中文的话,直接传会报错,得在headers里面加一项,还得把data编码成utf-8
还有你的filename,里面包括冒号这种特殊字符,会报错,得把逗号替换成其他符号,我用短横杠,你也可以用其他的
|