import requests
from bs4 import BeautifulSoup
from lxml import etree
import time
爬取网站图片
lj = "
url = "
resp0 = requests.get(url)
resp0.encoding = "utf-8"
#print(resp.text)
tp_list = []
img_list = BeautifulSoup(resp0.text, "html.parser")
#print(img_list)
imgs = img_list.find("ul", id="pins").find_all("a")
for img in imgs:
img_href = lj+img.get("href") # 拼接成网址
tp_list.append(img_href) # 将网址放在列表中
#print(img_href)
#print(tp_list)
for i in tp_list:
resp1 = requests.get(i) # 用循环依次去访问网站
resp1.encoding = "utf-8"
tree = etree.HTML(resp1.text)
divs = tree.xpath("/html/body/div[3]/div[1]/div[3]/p/a/img/@src")
print(divs)