使用美丽的汤时无法获得特定标签

Unable to get a particular tag while using beautiful soup

我想从 stack overflow 网站提取信息, 当我想获取问题的文本部分时:

import requests
from bs4 import BeautifulSoup
response=requests.get("https://whosebug.com/")
soup=BeautifulSoup(response.text,"html.parser",multi_valued_attributes=None)

for tag in soup.find_all('a',class_='question-hyperlink'):
    print(tag)

这在 all.I 处没有输出,我认为当我过滤 class 时出现了一些问题,但我不确定它是什么。

这个很好用:

import requests  
from bs4 import BeautifulSoup
response=requests.get("https://whosebug.com/questions")
soup=BeautifulSoup(response.text,"html.parser")
question=soup.select(".question-summary")

for a in question:
    print(a.select_one(".question-hyperlink").getText())

但是前者有什么问题呢?

您在第一个代码段的这一行的 url 中缺少 questions

response=requests.get("https://whosebug.com/")

这很好用:

import requests
from bs4 import BeautifulSoup

response = requests.get("https://whosebug.com/questions")
soup = BeautifulSoup(response.text, "html.parser")

for tag in soup.find_all('a', class_='question-hyperlink'):
    print(tag.getText(strip=True))

输出:

Pass a json object in function as a variable
iPhone Application Development in Windows 10 Platform
Jetty Websocket API Session
Exit from a multiprocessing Pool for loop using apply_async and terminate
bootstrap 5 grid layout col-md-6 not working correctly
R comparison (1) is possible only for atomic and list types
NeutralinoJS: error: missing required argument 'name'
Formatting text editor with Elementor

and so on ...

否则没有class这样的锚标签