python 爬虫爬取图片问题

python爬虫爬取网页图片无法显示问题,不知道是不是有反爬虫还是代码有问题,代码在回答栏

img

img

你题目的解答代码如下:

#coding=gbk
import requests
from io import BytesIO
from PIL import Image
from selenium import webdriver
import lxml.html
from selenium.webdriver.chrome.options import Options
opt = Options()
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_argument('--disable-blink-features')
opt.add_argument('--disable-extensions')
opt.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=opt)
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.huya.com/g/lol')#虎牙官网
html=driver.page_source
xp=lxml.html.fromstring(html)
u=xp.xpath('//span[@class="avatar fl"]')
for i in u:
    name=i.xpath('.//img/@alt')
    url=i.xpath('.//img/@data-original')  #改下
    print(url)
    name=name[0]
    url= url[0]
    if url[:6]=='https:':
        url=url
    else:
        url = 'https:'+url
    print(name,url)
    response = requests.get(url)
    image = Image.open(BytesIO(response.content))
    image.save(f'd:\w\{name}.png')

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

#coding=gbk
import requests
from io import BytesIO
from PIL import Image
from selenium import webdriver
import lxml.html
from selenium.webdriver.chrome.options import Options
opt = Options()
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_argument('--disable-blink-features')
opt.add_argument('--disable-extensions')
opt.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=opt)
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.huya.com/g/lol')#虎牙官网
html=driver.page_source
xp=lxml.html.fromstring(html)
u=xp.xpath('//span[@class="avatar fl"]')
for i in u:
    name=i.xpath('.//img/@alt')
    url=i.xpath('.//img/@src')
    print(url)
    name=name[0]
    url= url[0]
    if url[:6]=='https:':
        url=url
    else:
        url = 'https:'+url
    print(name,url)
    response = requests.get(url)
    image = Image.open(BytesIO(response.content))
    image.save(f'd:\w\{name}.png')



您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

我主页有爬取图片相关代码