python爬虫===全网表情包爬取

import requests
import re
import os
def get_url(url):
    response=requests.get(url)
    response.encoding='utf-8'
    url_addr=r''#正则表达式
    url_list=re.findall(url_addr,response.text)
    return url_list


def get_gif(url,name):
    response=requests.get(url)
    response.encoding='utf-8'
    with open('./gif/%d.gif'%name,'wb') as ft:
        # F: \\desktop\\Python_Spider
        # response.content从response中获取二进制文件
            if ft.write(response.content) :
                print("爬取成功:%s"%url)
            else:
                print("爬取失败:%s" % url)

if __name__=='__main__':
    url = input('请输入想要爬取的QQ表情包系列gif(地址为http://qq.yh31.com/zjbq/):\n')
    url_list=get_url(url)
    a=1
    for url in url_list:
        gif_url='http://qq.yh31.com'+url
        get_gif(gif_url,a)
        a+=1
    print("爬取结束")

python爬虫===全网表情包爬取_第1张图片

运行结果:
python爬虫===全网表情包爬取_第2张图片

你可能感兴趣的:(爬虫)