从图中的结果屏幕可以看到,类名是正确的,似乎没有错误。但我没有得到任何结果。from bs4 import BeautifulSoupfrom urllib.request import urlopenresponse = urlopen("https://www.naver.com")soup = BeautifulSoup(response, 'html.parser')for anchor in soup.select('span .realtime_item'): print(anchor)
3 回答
UYOU
TA贡献1878条经验 获得超4个赞
它对我有用:
from bs4 import BeautifulSoup
from urllib.request import urlopen
response = urlopen("https://www.naver.com")
soup = BeautifulSoup(response, 'html.parser')
for anchor in soup.select('.realtime_item'):
print(anchor)
print("\n\n")
慕桂英3389331
TA贡献2036条经验 获得超8个赞
您没有获得任何数据,因为 SPAN 没有类似realtime_item 的内容。尝试打印 soup 并查找该值是否存在,然后进行选择
from bs4 import BeautifulSoup
from urllib.request import urlopen
response = urlopen("https://www.naver.com")
soup = BeautifulSoup(response, 'html.parser')
print(soup)
添加回答
举报
0/150
提交
取消