码迷,mamicode.com
首页 > 其他好文 > 详细

乘胜追击

时间:2018-07-15 19:51:26      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:response   htm   with open   turn   open   image   write   nbsp   目标   

目标:汽车之家https://car.autohome.com.cn/pic/series/153-1-p5.html

 

#!/urs/bin/evn python
# -*- coding:utf-8 -*-
import requests
import re


def get_url(url):
    response = requests.get(url)
    response.encoding = "gb2312"
    r = <img src="(.*?)" alt=".*?">
    url_list = re.findall(r, response.text)
    return url_list


def get_jpg(url, name):
    response = requests.get(url)
    response.encoding = "gb2312"
    with open(r"D:\data\%d.jpg" % name, "wb") as ft:
        ft.write(response.content)


if __name__ == __main__:
    a = 1
    for i in range(1, 6):
        url_list = get_url("https://car.autohome.com.cn/pic/series/153-1-p%d.html" % i)

        for url in url_list:
            com_url = "http:" + url
            get_jpg(com_url, a)
            a += 1

 

技术分享图片

技术分享图片

乘胜追击

标签:response   htm   with open   turn   open   image   write   nbsp   目标   

原文地址:https://www.cnblogs.com/zqxqx/p/9314148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!