Skip to content

Commit cc529a5

Browse files
authored
Create doutu.py
1 parent ea540d0 commit cc529a5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

moumoubaimifan/doutu/doutu.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import os
3+
import requests,re
4+
5+
6+
def get_html(search_key, page):
7+
header = {
8+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
9+
'Host': 'www.fabiaoqing.com'
10+
}
11+
12+
key_url = 'https://fabiaoqing.com/search/bqb/keyword/{}/type/bq/page/{}.html'.format(search_key, page)
13+
14+
resp = requests.get(key_url, headers=header)
15+
resp.encoding='utf-8'
16+
return resp.text
17+
18+
def get_src(html):
19+
srcs = re.findall('<img class="ui image bqppsearch lazy" data-original="(.*?)" src="(.*?)" title="(.*?)"',html,re.S)
20+
return srcs
21+
22+
def downlaod(srcs, path):
23+
24+
from urllib.request import urlretrieve
25+
for item in srcs:
26+
print(item[2])
27+
urlretrieve(item[0], path + '\\' + item[2].replace('\n', '') + '.png')
28+
29+
30+
if __name__=="__main__":
31+
search_key = input("请输入需要的表情包:")
32+
33+
path = "D:\image\{}".format(search_key);
34+
35+
try:
36+
os.makedirs(path)
37+
except:
38+
pass
39+
40+
for i in range(5):
41+
html = get_html(search_key, i)
42+
srcs = get_src(html)
43+
if len(srcs) == 0:
44+
print("已经没有表情包了,下载完成了")
45+
downlaod(srcs, path)

0 commit comments

Comments
 (0)