运行结果
运行图片
from bs4 import BeautifulSoup
import requests
import urllib.request
data1 = []
data2 = []
path = 'C:/Users/zhangyang/Desktop/swift/'
def get_url(url):
web_data = requests.get(url)
soup = BeautifulSoup(web_data.text, 'lxml')
headerimgs = soup.select('#main-container > div > div.header > div.header-cover')
contentimgs = soup.select('img')
# for headerimg in headerimgs:
# #data1.append(headerimg.get('style'))
# data1 =data1[0][23:-2]
# print(data1)
for contentimg in contentimgs:
data2.append(contentimg.get('src'))
print(data2)
def get_pic(start, end):
for i in range(start, end):
get_url('http://weheartit.com/inspirations/taylorswift?page='+str(i))
# for url in data1:
# urllib.request.urlretrieve(url, path + url.split('/')[-2] + url.split('/')[-1])
# print('done')
for url in data2:
urllib.request.urlretrieve(url, path + url[-10:])
print('done')
get_pic(0, 1)
网友评论