代码如下:
import requests from bs4 import BeautifulSoup import re #1、对安居客网站进行get请求 url="https://sz.zu.anjuke.com" headers={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" } #设置伪装的浏览器的表头 response=requests.get(url,headers=headers) #对安居客网站进行get请求,并伪装成浏览器访问 response.encoding="utf-8" #设置网页编码 html=response.text #将网页的源代码赋值给html #2、解析网站并打印图片路径 soup=BeautifulSoup(html,'lxml') content=soup.findAll('img') #对网站的img标签进行查找并赋值给content for image in content: #遍历网站的图片标签 print(image.get("lazy_src")) #打印图片标签的lazy_src属性的值,即图片原始路径