复制
收藏
提问
全网

import requests url = 'https://mp.weixin.qq.com/s?__biz=MzUxNzk1ODQyMQ==&mid=2247525204&idx=1&sn=fbadab501a494ed00696a04e5b25af16&chksm=f9921d2ecee594387f84ae06139a69d693cb450ddb9815190848a890c7cdb21e6952bd3ac075&scene=27' # 替换为你想访问的网站 res = requests.get(url) import lxml.html import os connect = lxml.html.fromstring(res.text) images = connect.xpath('//div[@id="js_content"]/section/section/img[@class="rich_pages wxw-img"]/@src') # 保存图片到桌面 desktop_path = os.path.join(os.path.expanduser(r"C:\Users\Administrator\Desktop"), "images") os.makedirs(desktop_path, exist_ok=True) for i, image_url in enumerate(images): # 获取图片内容 response = requests.get(images) image_content = response.content # 保存图片到桌面 image_path = os.path.join(desktop_path, f"image_{i}.jpg") with open(image_path, 'wb') as file: file.write(image_content)查错

6月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题import requests url = 'https://mp.weixin.qq.com/s?__biz=MzUxNzk1ODQyMQ==&mid=2247525204&idx=1&sn=fbadab501a494ed00696a04e5b25af16&chksm=f9921d2ecee594387f84ae06139a69d693cb450ddb9815190848a890c7cdb21e6952bd3ac075&scene=27' # 替换为你想访问的网站 res = requests.get(url) import lxml.html import os connect = lxml.html.fromstring(res.text) images = connect.xpath('//div[@id="js_content"]/section/section/img[@class="rich_pages wxw-img"]/@src') # 保存图片到桌面 desktop_path = os.path.join(os.path.expanduser(r"C:\Users\Administrator\Desktop"), "images") os.makedirs(desktop_path, exist_ok=True) for i, image_url in enumerate(images): # 获取图片内容 response = requests.get(images) image_content = response.content # 保存图片到桌面 image_path = os.path.join(desktop_path, f"image_{i}.jpg") with open(image_path, 'wb') as file: file.write(image_content)查错

已完成理解import requests url = 'https://mp.weixin.qq.com/s?__biz=MzUxNzk1ODQyMQ==&mid=2247525204&idx=1&sn=fbadab501a494ed00696a04e5b25af16&chksm=f9921d2ecee594387f84ae06139a69d693cb450ddb9815190848a890c7cdb21e6952bd3ac075&scene=27' # 替换为你想访问的网站 res = requests.get(url) import lxml.html import os connect = lxml.html.fromstring(res.text) images = connect.xpath('//div[@id="js_content"]/section/section/img[@class="rich_pages wxw-img"]/@src') # 保存图片到桌面 desktop_path = os.path.join(os.path.expanduser(r"C:\Users\Administrator\Desktop"), "images") os.makedirs(desktop_path, exist_ok=True) for i, image_url in enumerate(images): # 获取图片内容 response = requests.get(images) image_content = response.content # 保存图片到桌面 image_path = os.path.join(desktop_path, f"image_{i}.jpg") with open(image_path, 'wb') as file: file.write(image_content)查错

展开阅读网页

更专业一些
转笔记
专业
import requests url = 'https://mp.weixin.qq.com/s?__biz=MzUxNzk1ODQyMQ==&mid=2247525204&idx=1&sn=fbadab501a494ed00696a04e5b25af16&chksm=f9921d2ecee594387f84ae06139a69d693cb450ddb9815190848a890c7cdb21e6952bd3ac075&scene=27' # 替换为你想访问的网站 res = requests.get(url) import lxml.html import os connect = lxml.html.fromstring(res.text) images = connect.xpath('//div[@id="js_content"]/section/section/img[@class="rich_pages wxw-img"]/@src') # 保存图片到桌面 desktop_path = os.path.join(os.path.expanduser(r"C:\Users\Administrator\Desktop"), "images") os.makedirs(desktop_path, exist_ok=True) for i, image_url in enumerate(images): # 获取图片内容 response = requests.get(images) image_content = response.content # 保存图片到桌面 image_path = os.path.join(desktop_path, f"image_{i}.jpg") with open(image_path, 'wb') as file: file.write(image_content)查错
不在提醒

更专业内容正在努力生成中
知识树
import requests url = 'https://mp.weixin.qq.com/s?__biz=MzUxNzk1ODQyMQ==&mid=2247525204&idx=1&sn=fbadab501a494ed00696a04e5b25af16&chksm=f9921d2ecee594387f84ae06139a69d693cb450ddb9815190848a890c7cdb21e6952bd3ac075&scene=27' # 替换为你想访问的网站 res = requests.get(url) import lxml.html import os connect = lxml.html.fromstring(res.text) images = connect.xpath('//div[@id="js_content"]/section/section/img[@class="rich_pages wxw-img"]/@src') # 保存图片到桌面 desktop_path = os.path.join(os.path.expanduser(r"C:\Users\Administrator\Desktop"), "images") os.makedirs(desktop_path, exist_ok=True) for i, image_url in enumerate(images): # 获取图片内容 response = requests.get(images) image_content = response.content # 保存图片到桌面 image_path = os.path.join(desktop_path, f"image_{i}.jpg") with open(image_path, 'wb') as file: file.write(image_content)查错
requests库如何发送GET请求?
lxml库如何解析HTML?
如何使用xpath定位网页元素?

以上内容由AI搜集生成,仅供参考

在线客服