猿问

为什么无法爬取所需图片,代码都ok的

import requests
from lxml import etree
bd = requests.get(' 
bd.encodong='ISO-8859-1'
html =etree.HTML(bd.text)
h1 = html.xpath('//*[@id="blk_detail_info"]/div[1]/div/img/@src')[0]
h2 ='http:'+ h1
t=requests.get(h2)
with open('ez.jpg','wb') as f:
    f.write(t.content)
    
    
    
 错误提示如下:
Traceback (most recent call last):
  File "F:/python/爬虫学习/EZ.py", line 8, in <module>
    h1 = html.xpath('//*[@id="blk_detail_info"]/div[1]/div/img/@src')[0]
IndexError: list index out of range


慕丝7585652
浏览 935回答 3
3回答

戴高兴

URL在哪
随时随地看视频慕课网APP
我要回答