代码分享—python爬取表情包

功能描述:

爬取永恒网金馆长QQ表情系列表情包

代码如下

import requests

from bs4 import BeautifulSoup

url_pic = []

##下载图片

def download(url,c):

response = requests.get(url,stream = True)

print("正在下载第%d张图片"%c)

#图片存放地址,可更改

with open("C:/Users/admin/Desktop/pic/"+"picture_" + str(c)+".jpg","wb") as fd:

for chunk in response.iter_content(128):

fd.write(chunk)

##获取图片链接

def get_url(url_s):

res = requests.get(url_s)

res.encoding = "utf-8"

soup = BeautifulSoup(res.text,"lxml")

html = soup.select(".c_content_overflow > p > img")

for b in range(len(html)):

url_w ="http://qq.yh31.com/" + html[b]["src"]

url_pic.append(url_w)

if __name__ == '__main__':

for a in range(50):#50为页数,最大为96

url_c = "http://qq.yh31.com/zjbq/0551964_" + str(a) + ".html"

get_url(url_c)

for c in range(len(url_pic)):

download(url_pic[c],c)

py文件获取请扫码关注公众号《python练手项目实战》,后台回复“表情包”

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180725A0JSAM00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 yunjia_community@tencent.com 删除。

扫码关注云+社区

领取腾讯云代金券