# -*- coding: UTF-8 -*-
import requests
import re
import random
import string
def write_file(file, content):
with open(file, "wb") as f:
f.write(content)
print "done"
def down_picture(file, url, headers):
response = requests.get(url, headers)
if response.status_code == 200:
write_file(file, response.content)
def for_get_picture(url):
headers = {}
response = requests.get(url, headers = headers)
print "code: %d " % (response.status_code)
patterm = re.compile("src=(.*.jpg)")
if response.status_code == 200:
content = response.content
list = patterm.findall(content)
str1 = str(list)
image_list = str1.split("\"")
for i in image_list:
if i.endswith("jpg"):
jpg_url = "https://pic.netbian.com" + i
print jpg_url
radom = ''.join(random.sample(string.ascii_letters + string.digits, 8))
#print salt
file = "D:\\python\\download\\" + radom + ".jpg"
print file
down_picture(file, jpg_url, "")
#write_file("D:\\python\\download\\1.jpg", response.content)
url = "https://pic.netbian.com/4kmeinv/index_3.html"
for i in range(4,175,1):
url1 = "https://pic.netbian.com/4kmeinv/index_%s.html" % (i)
#print url1
for_get_picture(url1)
Python requests 爬虫实战1
最新推荐文章于 2024-10-10 15:26:20 发布