1. 程式人生 > >用python爬取美女圖片

用python爬取美女圖片

import urllib.request
import os

for i in range(2000, 2400):
if not os.path.exists(‘tupian/’ + str(i)):
os.makedirs(‘tupian/’ + str(i))
for j in range(60):
try:
url = ‘http://img1.mm131.me/pic/’ + str(i) + ‘/’ + str(j) + ‘.jpg’
print(url)
# urllib.request.urlretrieve(url, ‘lala.jpg’)
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36’,
‘Referer’: ‘

https://www.sogou.com/link?url=DSOYnZeCC_o7btUgpK402wmc9YOcsOr4cOOT57O29F8
}
request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
with open(‘tupian/’ + str(i) + ‘/’ + str(j) + ‘.jpg’, ‘wb’) as fp:
fp.write(response.read())
except Exception as e:
print(‘下載失敗,下載下一條’)
break