程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-06(1)

妹子图XXOO

发布于2019-08-06 10:19     阅读(989)     评论(0)     点赞(1)     收藏(5)


依葫芦画瓢 

用字符串查找图片地址下载 

图片放在当前目录 

GIF下载下来不会动.....

 

 

import urllib.request
import time

def open_url(url):
    #return htmlpage
    print(url)
    req = urllib.request.Request(url)
    req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
    response = urllib.request.urlopen(req)
    return response.read()

def getInitialpage():
    #return how many pages we have
    url = "http://jandan.net/ooxx"
    html = open_url(url)
    html = html.decode("utf-8")
    index = html.find("span class=\"current-comment-page\"")
    beginindex = html.find("[" , index)
    endindex = html.find("]" , index)
    initialpage = html[(beginindex+1) : endindex]
    return initialpage

def getpiclist(pageurl):
    html = open_url(pageurl)
    html = html.decode("utf-8")
    piclist = list()
    for i in range(html.count("[查看原图]</a><br /><img")):
        index = html.find("[查看原图]</a><br /><img")
        html=html[index:]
        beginindex = html.find("\"")
        endindex = html.find("\"" , (beginindex+1))
        picurl = html[beginindex+1:endindex]
        html = html[endindex:]
        piclist.append(picurl)
    return piclist

def savepic(piclist):
    for picurl in piclist:
        html = open_url("http:{}".format(picurl))
        filename = picurl.split("/")[-1]
        print(filename)
        with open(filename , "wb") as f:
            f.write(html)
        time.sleep(1)

def test(page):
    initialpage = int(getInitialpage())
    for i in range((initialpage-page),(initialpage+1)):
        pageurl = "http://jandan.net/ooxx/page-{}#comments".format(i)
        piclist = getpiclist(pageurl)
        savepic(piclist)        
if __name__ == "__main__":
    test(1)

 

 

 

 

 



所属网站分类: 技术文章 > 博客

作者:短发越来越短

链接:https://www.pythonheidong.com/blog/article/7575/909a60805ccf2d37b1fb/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

1 0
收藏该文
已收藏

评论内容:(最多支持255个字符)