-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.py
43 lines (35 loc) · 1.1 KB
/
word.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
#codeing:utf-8
import requests
from bs4 import BeautifulSoup
def baidu_index(word=" "):
headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.7 Safari/537.36"}
info=[]
page=0
while page<=90:
payload = {'wd': word,'pn':page,'ie':"utf-8","tn":"baiduhome_pg"}
req=requests.get("https://www.baidu.com/s",params=payload,headers=headers)
print(req.url)
soup=BeautifulSoup(req.text,'lxml')
for i in soup.select(".c-container "):
if i.select(".c-showurl"):
domain=i.select(".c-showurl")[0].get_text().strip()
else:
domain=""
info.append({'id':i["id"],'srcid':i['srcid'],'domain':domain,'title':i.h3.get_text(),'tpl':i['tpl'],'data-click':i['data-click']})
page+=10
print(info)
return info
def get_index_baidu(*words):
for word in words:
for index in baidu_index(word):
if 'www.vrnew.com' in index['domain']:
print('{word}排名在{index}'.format(word=word,index=index['id']))
print(index)
else:
pass
def main():
words=["vr"]
get_index_baidu(*words)
if __name__ == '__main__':
main()