import requests
res=requests.get('http://news.sina.com.cn/china/')
res.encoding="utf-8"
from bs4 import BeautifulSoup
soup=BeautifulSoup(res.text,'html.parser')
a=soup.select('a')
for i in a:
print (i[href])
我想要输出每个链接的网址,但是上面的代码 结果是
错误:print (i[href])
NameError: name 'href' is not defined
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号