zoukankan      html  css  js  c++  java
  • Python 小程序之 恋爱表情包爬取

    虽然恋爱跟我一毛钱关系没有,,但是我还是想爬它

    实验爬取网址:http://qq.yh31.com/zjbq/1491124.html

    # -*- coding: utf-8 -*-
    # @Time    : 2018/3/24 22:18
    # @Author  : TanRong
    # @Software: PyCharm
    # @File    : bqb.py
    
    import requests
    import re
    
    def getSubUrls(website):
        response = requests.get(website)
        response.encoding = 'utf-8'   #必须加上网页编码格式
        subUrlAddr = r'<img src="/tp/zjbq/(.*?)" />'
        subUrlList = re.findall(subUrlAddr,response.text) #第二个位置参数是字符串,而response是html,所以需要response.text
        print(subUrlList)
        return subUrlList
    
    def getImage(url, name):
        response = requests.get(url)
        with open('C:\Users\pc\Desktop\images\%d.gif'%name, 'wb') as f:
            f.write(response.content)
    
    if __name__ == '__main__':
        website = 'http://qq.yh31.com/zjbq/1491124.html'
        subUrlList = getSubUrls(website)
    
        name = 1
        for subUrl in subUrlList:
            url = 'http://qq.yh31.com/tp/zjbq/' + subUrl
            getImage(url, name)
            name += 1
  • 相关阅读:
    饿了么 PostgreSQL 优化之旅
    kubernetes 滚动更新发布及回滚
    kubernetes yaml
    mongodb安装
    node.js安装
    linux输出换行
    把token放入请求头
    $.ajaxSetup
    js前端读取文件内容
    v-echarts安装
  • 原文地址:https://www.cnblogs.com/tanrong/p/8641939.html
Copyright © 2011-2022 走看看