类似这种,正好看到有网页有这种表情包的汇总:
https://mp.weixin.qq.com/s?__biz=MzA5MTY0NTYyOQ
爬它
# -*- coding:utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import requests
import os
url = input("请输入百度图片网址:")
FILENAME = input("请输入要存放的文件夹名称(切记要输英文名!):")
browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
browser.get(url)
time.sleep(5)
#这个阶段自己拉网页
# while cnt>0:
# go_scroll(num,browser)
# cnt = cnt-1
# time.sleep(0.5)
html = browser.page_source
soup = BeautifulSoup(html, 'lxml')
images = soup.find_all('img', {'class': '__bg_gif'})
#figures = soup.find_all('imgitem')
#print(figures)
root = r'D:\crawl_download'
if os.path.exists(root) is not True:
os.mkdir(root)
print("root created!"+root)
src =""
path2 = os.path.join(root,FILENAME)
if os.path.exists(path2) is not True:
os.mkdir(path2)
print("百度图片存放地址"+path2)
cnt = 1
for item in images:
try:
src= item['data-src']
pic = requests.get(src).content
print(src)
cnt=cnt+1
with open(os.path.join(path2,src[-50:-30])+'.gif','wb') as f:
f.write(pic)
f.close()
except Exception:
print(repr(Exception))
continue
print('download successful')
browser.close()
运行过程
结果:
over