• python


    #!/usr/bin/python3
    # -*- coding: UTF-8 -*-
     
    import urllib
    from urllib.parse import urlencode
    from urllib.request import Request, urlopen
    import re
    import time
    import os
     
    times = 0

    def download_pic(pic_url,root_url,down_times):
    url = pic_url
    Referer = root_url
    down_time = down_times
    headers = {
    'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
    'Referer':Referer
    }
    down_path = str(down_time)+'.jpg'
    print (down_path)
    requests = Request(url, headers=headers)
    data = urlopen(requests).read()
    with open(down_path, 'wb') as f:
    f.write(data)
    f.close()
    down_time+=1
    return down_time




    def jiexi_rootPic_url(next_rootUrl,down_times):
    url = next_rootUrl
    headers = {
    'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
    }
    downtime = down_times
    request_url = Request(url, headers=headers)
    response = urlopen(request_url).read().decode("utf-8")
    pattern = re.compile('<img src="(.*?)"', re.IGNORECASE)
    pic_path = pattern.findall(response)
    for i in pic_path:
    print ('download_prepare')
    downtime = download_pic(i,url,downtime)
    time.sleep(2)
    print(i)
    return downtime


    def jiexi_url(root_url,down_times):
    headers = {
    'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
    }
    downtime = down_times
    url = root_url
    request_url = Request(url, headers=headers)
    html = urlopen(request_url).read().decode("utf-8")
    response = re.compile('/rnyy(.*?).html', re.IGNORECASE)
    all_next_root = response.findall(html)
    for i in all_next_root:
    path = 'http://mmff30.com/rnyy'+i+'.html'
    print (path)
    # downtime = jiexi_rootPic_url(path,downtime)



    jiexi_url('http://mmff30.com/rwmy_9_14.html',0)
  • 相关阅读:
    day56 js收尾,jQuery前戏
    解决:No module named 'haystack.urls'
    用PicGo+Gitee(码云)搭建Markdown图床
    Python正课138 —— 基础扩展4 django
    Python正课140 —— DRF 进阶1 序列化、增删改查
    Markdown基本语法
    Python正课139 —— DRF 入门1
    用PicGo+GitHub+Typora搭建个人图床
    解决django.core.exceptions.ImproperlyConfiguredmysqlclient 1.3.13 or
    解决:Django中AttributeError:'str'objects has no attribute 'decode'
  • 原文地址:https://www.cnblogs.com/ytCui/p/13053457.html
Copyright © 2020-2023  润新知