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)查错」
展开阅读网页