from bs4 import BeautifulSoup
import urllib.request
url=urllib.request.urlopen("https://www.theguardian.com/international/rss")
xml=BeautifulSoup(url,features='xml')
for item in xml.findAll('link')[3]:
news=urllib.request.urlopen(item.text).read()
print(news)
当我运行此代码时,它会抛出错误:AttributeError: 'NavigableString' object has no attribute 'text'
。我怎么能解决这个问题我是编码的新手,非常欢迎任何帮助。谢谢
答案 0 :(得分:0)
检查这种方式我相信它会起作用。
from bs4 import BeautifulSoup
import urllib.request
url = urllib.request.urlopen("https://www.theguardian.com/international/rss")
xml = BeautifulSoup(url, features='xml')
for item in xml.findAll('link')[3]:
news = urllib.request.urlopen(item).read()
print(news)