网站建设资源,构建网站的安全,西安网站开发联系方式,导购类网站模板当查看源代码#xff0c;发现网址在thumbURL之后时#xff0c;用此代码:
# 当查看源代码#xff0c;发现网址在thumbURL之后时#xff0c;用此代码:import requestsheaders {User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121… 当查看源代码发现网址在thumbURL之后时用此代码:
# 当查看源代码发现网址在thumbURL之后时用此代码:import requestsheaders {User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0,Accept:text/html,application/xhtmlxml,application/xml;q0.9,image/avif,image/webp,*/*;q0.8,Accept-Encoding:gzip, deflate, br,Accept-Language:zh-CN,zh;q0.8,zh-TW;q0.7,zh-HK;q0.5,en-US;q0.3,en;q0.2
}url input(请输入你想保存的图片的网址)
response requests.get(url, headers headers)
print(response)
print(response.status_code)file input(请输入你想图片保存在的文件夹名称)import os
os.makedirs(f./{file}, exist_ok True)
# 新建目录用于存储图片
# def makedirs(name, mode0o777, exist_okFalse):
# 参数说明
# name用于指定要创建目录的路径。
# mode指定目录的模式默认模式为八进制的 777。类似于 chmod() 方法。
# exist_ok可选参数如果值为 False当要创建的目录已经存在时抛出 FileExistsError 异常如果值为True
# 当要创建的目录已经存在时不会抛出异常。默认值为 False。import re
html response.text
image_url_list re.findall(thumbURL:(.*?),, html, re.S)
# 用于查找得到thumbURL后面的图片网址目前还不会正则表达式# print(image_url_list)
q 0
for url in image_url_list:# print(url)resrequests.get(url)pictureres.contentq1with open(f{file}\\{q}.jpg,modewb) as f:f.write(picture)# 在小猫文件夹下保存图片以q为图片文件名 # 当用requests.get请求得到的源代码是html文件每一行是一个标签时可以用此代码
# 当用requests.get请求得到的源代码是html文件每一行是一个标签时可以用此代码
import requests
from bs4 import BeautifulSoupheaders {User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0,Accept:text/html,application/xhtmlxml,application/xml;q0.9,image/avif,image/webp,*/*;q0.8,Accept-Encoding:gzip, deflate, br,Accept-Language:zh-CN,zh;q0.8,zh-TW;q0.7,zh-HK;q0.5,en-US;q0.3,en;q0.2
}url input(请输入你想保存的图片的网址)
response requests.get(url, headers headers)
print(response)
print(response.status_code)file input(请输入你想图片保存在的文件夹名称)
# responserequests.get(https://www.umei.cc/meinvtupian/)
response.encodingutf-8
# print(response.text)
soupBeautifulSoup(response.text,html.parser)
# print(soup)import os
os.makedirs(f./图片/{file}, exist_okTrue)lis soup.find_all(div,class_taotu-main)
# print(a)
print(*********)q0t 0
for l in lis:if(t 0):print(l)t 1pl.find_all(img)for i in p:pici.get(data-original)print(pic)resrequests.get(pic)pictureres.contentq1with open(f图片/{file}\\{q}.jpg,modewb) as f:f.write(picture)