def ask(url):
head = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"}
re = urllib.request.Request(url=url,headers=head)
res = urllib.request.urlopen(re)
html = res.read().decode('utf-8')
return html
findload = re.compile('<img.*data-original="(.*?)"')
def download_img(baseurl):
html = ask(baseurl)
soup = BeautifulSoup(html,'html.parser')
k=0
for item in soup.find_all('div',class_='list'):
item = str(item)
tupian = re.findall(findload,item)[0]
url = "http:"+tupian #注意图片路径加上http:
name = "D:\\妹子图片\\" #路径
name = name + str(k) + ".jpg"
k+=1
img = urllib.request.urlopen(url) #打开图片
f = open(name, 'wb') #打开本地路径
f.write(img.read()) #写进去
f.close
import re
import xlwt
import urllib.request,parser
from bs4 import BeautifulSoup
def ask(url):
head = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"}
re = urllib.request.Request(url=url,headers=head)
res = urllib.request.urlopen(re)
html = res.read().decode('utf-8')
return html
def download_img(baseurl):
html = ask(baseurl)
soup = BeautifulSoup(html,'html.parser')
k=0
for item in soup.find_all('div',class_='list'):
item = str(item)
tupian = re.findall(findload,item)[0]
url = "http:"+tupian
name = "D:\\妹子图片\\"
name = name + str(k) + ".jpg"
k+=1
img = urllib.request.urlopen(url)
f = open(name, 'wb')
f.write(img.read())
f.close
findload = re.compile('<img.*data-original="(.*?)"')
url = "http://699pic.com/tupian/xiaojiejie.html"
download_img(url)