吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11140|回复: 33
收起左侧

[Python 转载] 斗图神器——python让你斗图无敌

  [复制链接]
18382747915 发表于 2019-4-17 16:02
本帖最后由 18382747915 于 2019-4-17 16:04 编辑

你还在为斗图输了而懊恼嘛,你还在为找图到处瞎J8乱跑吗,python爬虫来啦!
今天为了跟别人斗图随便写的,哈哈,勿喷

[Python] 纯文本查看 复制代码
from os import mkdir
import requests,re

session=requests.session()
def bqb(title):
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0',
        'Host': 'www.fabiaoqing.com'
    }
    url="https://www.fabiaoqing.com/"
    session.get(url=url,headers=header)
    url="https://www.fabiaoqing.com/search/search/keyword/%s"%title
    req= session.get(url=url,headers=header)
    key=re.findall('<a class="item" href="/search/search/keyword/(.*?)/type/bq/page/(.*?).html">',req.text,re.S)[0][0]
    html = re.findall('<a class="item" href="/search/search/keyword/%s/type/bq/page/(.*?).html">'%key, req.text, re.S)
    b = {}
    c = b.fromkeys(html)
    liststr=list(c.keys())
    liststr.append("1")
    mkpath = "F:/%s/"%title
    # 调用函数
    try:
        mkdir(mkpath)
    except:
        print("文件夹已存在")
    count =0
    for i in liststr:
        url="https://www.fabiaoqing.com/search/search/keyword/%s/type/bq/page/%s.html"%(key,i)
        req=session.get(url=url, headers=header)
        html=req.text
        html_img=re.findall('<img class="ui image bqppsearch lazy" data-original="(.*?)" title="(.*?)"',html,re.S)
        html_img_link=html_img
        for x in html_img_link:
            count = count + 1;
            print("正在下载第%s张"%count)
            title=x[1]+str(count)
            imgurl=x[0]
            a = requests.get(imgurl).content
            try:
                with open('{}{}.jpg'.format(mkpath,title), 'wb')as wj:
                    wj.write(a)
            except:
                print()
    print("下载成功")
if __name__=="__main__":
    title=input("请输入表情包名称:")
    bqb(title)


1.png

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
绝版coco + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 18382747915 发表于 2020-2-3 21:11
什么舟来着 发表于 2020-2-3 15:18
大神们为什么用你们的代码复制进去都无法运行啊

环境问题 如有问题 看我呢称
hadeswillice 发表于 2020-12-30 10:04
Traceback (most recent call last):
  File "d:/pycode/test.py", line 46, in <module>
    bqb(title)
  File "d:/pycode/test.py", line 13, in bqb
    key=re.findall('<a class="item" href="/search/search/keyword/(.*?)/type/bq/page/(.*?).html">',req.text,re.S)[0][0]
IndexError: list index out of range
我是出现这个报错了,这个bqb的变量怎么会溢出呢
小涵 发表于 2019-4-17 16:22
supremego 发表于 2019-4-17 16:29
秀啊。。。
头像被屏蔽
errorhex404 发表于 2019-4-17 16:31
提示: 作者被禁止或删除 内容自动屏蔽
李民秀 发表于 2019-4-17 16:47
感谢楼主分享,支持一下!
WangAOA 发表于 2019-4-18 09:53
对有些人很有用,,,
lu_ 发表于 2019-4-21 09:31
楼主这是什么编辑器
YeMelody 发表于 2019-4-21 10:52
那么问题来了 他保存在了哪里。。。
 楼主| 18382747915 发表于 2019-4-21 15:58
YeMelody 发表于 2019-4-21 10:52
那么问题来了 他保存在了哪里。。。

F盘 文件夹名是你的搜索名
CrissKG 发表于 2019-8-24 16:57
这个怎么搞啊?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-19 15:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表