爬取http://www.doutula.com网站表情包
程序员文章站
2022-03-26 14:37:01
...
import requests
from bs4 import BeautifulSoup
def main(n):
for i in range(n):
url = f’http://www.doutula.com/photo/list/?page={i}’
response = requests.get(url=url)
soup = BeautifulSoup(response.text, 'html.parser')
div = soup.find(name='div', attrs={"class": 'page-content text-center'})
a_list = div.find_all(name="a")
for a in a_list:
img = a.find('img')
img_name = img.get('alt')
img_url = img.get('data-backup')
# print(img_name, img_url)
if img_name and img_url:
try:
with open('表情包/%s.jpg' % img_name, 'wb')as f:
ret_img = requests.get(url=img_url)
f.write(ret_img.content)
except Exception:
continue
main(5)
上一篇: Python 网络爬虫---爬取表情包
下一篇: Unity3D_Socket通信