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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9959|回复: 100
收起左侧

[Python 转载] python爬取n多张养眼福利图

  [复制链接]
三木猿 发表于 2020-9-4 14:53
之前写了个爬取漫画的,发现貌似喜欢的人不是很多呀,在贴吧转了会后发现,正经人们喜欢的是这种类型的由于代码量不大,就不加什么注释了,兄弟们自己研究研究吧
[Python] 纯文本查看 复制代码
import time
import requests
import os

from urllib3.connectionpool import xrange


def get_document(url):
    # print(url)
    try:
        get = requests.get(url)
        data = get.content
        get.close()
    except:
        time.sleep(3)
        try:
            get = requests.get(url)
            data = get.content
            get.close()
        except:
            time.sleep(3)
            get = requests.get(url)
            data = get.content
            get.close()
    return data


def download_img(count):
    for i in xrange(count):
        src = "https://lns.hywly.com/a/1/" + str(i)+"/"
        for j in xrange(20):
            document = get_document(src + str(j) + '.jpg')
            if str(document).find("404 Not Found") > 0:
                break
            path = 'd:/SanMu/image/'+str(i)+'/'
            if not os.path.exists(path):
                os.makedirs(path)
            open(path+str(j)+'.jpg', 'wb').write(document)


download_img(1000)

image.png

免费评分

参与人数 30吾爱币 +27 热心值 +26 收起 理由
Sheng——zac + 1 热心回复!
zqh888888888 + 1 + 1 谢谢@Thanks!
Applepeel + 1 + 1 我很赞同!
eyesstworld + 1 + 1 现在还能用
我真牛逼哈哈哈 + 1 + 1 我很赞同!
jalonewy + 1 + 1 两个版本都能运行,但是图的可看质量太差了!
矢岛舞美 + 1 + 1 我很赞同!
nanhai31 + 1 热心回复!
lr23653141 + 1 + 1 热心回复!
Qly520 + 1 谢谢@Thanks!
miaosha_li + 1 + 1 谢谢@Thanks!
doug16888 + 1 + 1 用心讨论,共获提升!
hshcompass + 1 + 1 热心回复!
中盛 + 1 + 1 谢谢@Thanks!
无畏前行 + 1 谢谢@Thanks!
深水夜藏 + 1 + 1 我很赞同!
从零学习的歪经小 + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
killua2011 + 1 + 1 热心回复!
bensonz + 1 + 1 鼓励转贴优秀软件安全工具和文档!
云儿筱筱 + 1 谢谢@Thanks!
时光书窝 + 1 + 1 谢谢@Thanks!
海天 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
feqqibe + 1 + 1 我很赞同!
MYLQG2ZHX + 1 + 1 我很赞同!
李安南 + 1 + 1 正经人谁看漫画啊,你看吗?
Feelingone + 1 感谢有你
zhangweiyi9 + 1 + 1 22#楼的建议可以采纳!
c03xp + 1 我很赞同!
hacksz + 2 + 1 谢谢@Thanks!
sktfaker + 1 热心回复!

查看全部评分

本帖被以下淘专辑推荐:

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

 楼主| 三木猿 发表于 2020-9-4 15:16
如果评分够多,就发多线程版,哼,老想白嫖
 楼主| 三木猿 发表于 2020-9-4 15:51
多线程版,哎,记得评分啊,我想升个级
[Python] 纯文本查看 复制代码
import threading
import time
import os
import requests
from urllib3.connectionpool import xrange


def get_document(url):
    # print(url)
    try:
        get = requests.get(url)
        data = get.content
        get.close()
    except:
        time.sleep(3)
        try:
            get = requests.get(url)
            data = get.content
            get.close()
        except:
            time.sleep(3)
            get = requests.get(url)
            data = get.content
            get.close()
    return data


def download_img(start, count):
    for i in xrange(start, count):
        src = "https://lns.hywly.com/a/1/" + str(i) + "/"
        for j in xrange(50):
            document = get_document(src + str(j) + '.jpg')
            if str(document).find("404 Not Found") > 0:
                break
            path = 'd:/SanMu/image/' + str(i) + '/'
            if not os.path.exists(path):
                os.makedirs(path)
            open(path + str(j) + '.jpg', 'wb').write(document)


thread_list = []
for i in xrange(0, 3):#想要几个线程就把3改成几
    thread = threading.Thread(target=download_img, args=(i * 1000, (i + 1) * 1000))
    thread_list.append(thread)
for thread in thread_list:
    thread.start()
for thread in thread_list:
    thread.join()
while 1:
    break
MancoCL 发表于 2020-9-4 15:02
我想看不穿衣服的那种

免费评分

参与人数 2吾爱币 +2 收起 理由
郭帅 + 1 我很赞同!
anandyuan + 1 感谢您的宝贵建议,我们会努力争取做得更好!

查看全部评分

judgecx 发表于 2020-9-4 14:57
  他们只想白嫖哈哈哈白嫖怪
14境左右 发表于 2020-9-4 15:00
都是正经人
Ocisl 发表于 2020-9-4 15:04
老哥 刚才运行了一下这是怎么回事啊
完全不懂编程的色批 大佬给指条明路啊

Microsoft Windows [版本 10.0.17763.1397]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\Ocisl>python C:\Users\Ocisl\Desktop
D:\Users\Ocisl\AppData\Local\Programs\Python\Python37\python.exe: can't find '__main__' module in 'C:\\Users\\Ocisl\\Desktop'

C:\Users\Ocisl>
芒果1981 发表于 2020-9-4 15:09
看到这么多好图我也想试一下,可是把代码复制到pycharm里面点运行 后会这样 :C:\Users\admin\Desktop\python_work\venv\Scripts\python.exe C:/Users/admin/Desktop/python_work/123.py
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\python_work\123.py", line 2, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Process finished with exit code 1
 楼主| 三木猿 发表于 2020-9-4 15:12
芒果1981 发表于 2020-9-4 15:09
看到这么多好图我也想试一下,可是把代码复制到pycharm里面点运行 后会这样 :C:%users\admin\Desktop\pyth ...

缺包,网上有下载requests包的教程
 楼主| 三木猿 发表于 2020-9-4 15:14
Ocisl 发表于 2020-9-4 15:04
老哥 刚才运行了一下这是怎么回事啊
完全不懂编程的色批 大佬给指条明路啊

你都没指出来运行那个文件呀,
python  C:\Users\Ocisl\Desktop\test.py
mokjf 发表于 2020-9-4 15:15
有没有教程教人怎么爬资源,新手想入手爬一下资源,例如爬视频或者图书的之类的
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-4-28 02:39

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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