python KeyError: 'src'
这是我的代码
import requests
from bs4 import BeautifulSoup
html_url="http://www.xghylt.com/thread-7085136-1-1.html"
headers={'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"}
response=requests.get(html_url,headers=headers)
print(response)
#print(response.text)
all_img=BeautifulSoup(response.text,'lxml').find('div',class_="t_fsz").find_all('img')
lenth = len(all_img) #计算集合的个数
for i in range(lenth):
img_url=all_img[i].attrs['src']
print("kaishi"+img_url)
print(img_url)
这是我的控制台的错误提示
Traceback (most recent call last):
File "I:/Python/Py/huaiyinluntan/meitu.py", line 12, in <module>
img_url=all_img[i].attrs['src']
KeyError: 'src'