使用Python Requests伪装成浏览器请求百度360获取关键词批量排名
#!/usr/local/python/bin/python3.7
import requests,re,time,random,string
#error='360搜索_访问异常出错' #360
error="location.href.replace" #baidu
url=["www.a.com", "www.b.com"] #你要查询的网址,可以是多个
uaList = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36']
with open('a.txt','r') as f: #查询的关键词保存在同一目录下a. txt
c=list(f.readlines())
for i in c:
ci=(i.rstrip("\n"))
u='https://www.baidu.com/s?wd={}'.format(ci)
#u='https://so.com/s?&q={}&pn=1'.format(ci)
sj=random.randrange(10,15)
#time.sleep(sj)
header={'User-Agent': random.choice(uaList)}
a=requests.get(u,headers=header).content.decode('utf-8')
if error in a:
print(ci,"error")
continue
lb=re.findall(r"\"text-decoration\:none\;\"\>(.*)?\;\",a)
strlb=''.join(lb)
z="不在"
for i in url:
if i in strlb:
z="在"
break
print(ci,z)
©著作权归作者所有:来自51CTO博客作者薛文昌的原创作品,如需转载,请注明出处,否则将追究法律责任
每一份赞赏源于懂得
赞赏
0人进行了赞赏支持
薛文昌
55篇文章,125W+人气,7粉丝