importurllib.request
frombs4importBeautifulSoup
importrequests
data=[]
url=['http://www.tara-china.cn/TARA_Gallery/TARA_Picture/2015/11/07/1947562240_{}.html'.format(str(i))foriinrange(2,19)]
url2=['http://www.tara-china.cn/TARA_Gallery/TARA_Wallpaper/2015/11/07/1902192236_{}.html'.format(str(i))foriinrange(2,8)]
url_base='http://www.tara-china.cn'
defdownload_t_ara(url):
wb_data=requests.get(url)
soup=BeautifulSoup(wb_data.text,'lxml')
images=soup.select(' p > img')
forimageinimages:
data.append(url_base+image.get('src'))
# count=0
forurl1inurl2:
download_t_ara(url1)
# count=count+1
# if count==3:
# break
file_path='C:/Users/xilixjd/Desktop/Important file/python/爬虫/1/1_4/T-ara/'
file_path1='C:/Users/xilixjd/Desktop/Important file/python/爬虫/1/1_4/T-ara1/'
deffile_download(file_path,data):
count1=0
forimage_urlindata:
count1=count1+1
urllib.request.urlretrieve(image_url,file_path+str(count1)+'.jpg')
file_download(file_path1,data)
'''
image_url='http://www.tara-china.cn/UploadFiles/TARA_Gallery/2015/11/201511071943301109.jpg'
urllib.request.urlretrieve(image_url,'C:/Users/xilixjd/Desktop/Important file/python/爬虫/1/1_4/T-ara/1.jpg')
'''