• 爬zol村壁纸篇


    # -*- coding: utf-8 -*-
    # @Author  : Jackzz
    
    import requests,os
    from pyquery import PyQuery as pq
    
    def get_request(url):
        #构造请求头
        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
        }
        html = requests.get(url=url, headers=headers).content.decode("gb2312")#网站编码格式是2312具体看网页源码
        # print(html)
        doc =pq(html)
        items = doc('.photo-list-padding').items()
        for item in items:
            # print(item)
            url_img = item.find('img').attr('src')
            # print(url_img) #打印每个封面url
            name = item.find('span').attr('title')
            print(name)#获取每个封面的标题
            # download_url = requests.get(url=url_img,headers=headers).content
            # print("下载的图片: %s  路径: %s"%(name,url_img))
            # try:
            #     with open("./imgs/"+name+".jpg","wb") as file:
            #         file.write(download_url)
            # except OSError as e:
            #     continue
    
    
    if __name__ == '__main__':
        #获取绝对路径拼接
        file_path=os.path.join(os.getcwd(),"imgs")
        #判断当前路径是否存在,不存在则创建路径
        if not os.path.exists(file_path):
            #创建路径
            os.makedirs(file_path)
    #多页爬取设置,爬取一到五页图片
        for i in range(1,5):
            url="http://desk.zol.com.cn/pc/%s"%str(i)+'.html'
            get_request(url)
    

      

  • 相关阅读:
    CSS3圆角详解
    纯CSS绘制三角形(各种角度)
    jquery实现文字上下无缝滚动
    选择select里面某个option触发的事件
    倒计时
    移动端弹出层加遮罩后禁止滑动
    终端连接oschina 生成SSH公钥
    兼容所有的浏览器透明度代码
    背景颜色渐变效果设置
    Linux下搜索文件命令whereis/which/find/locate
  • 原文地址:https://www.cnblogs.com/jackzz/p/10698665.html
Copyright © 2020-2023  润新知