使用BeautifulSoup无法提取指定元素中文本的问题求助
使用BeautifulSoup无法提取指定元素中文本的问题求助

以下是我目前的代码:
import requests from bs4 import BeautifulSoup url = 'https://www.tori.fi/recommerce/forsale/item/22362242' headers = {"User-Agent": "Mozilla/5.0"} response = requests.get(url, headers=headers) if response.status_code == 200: soup = BeautifulSoup(response.text, "html.parser") section = soup.find("section", class_="flex gap-8 flex-wrap mb-24") #print(section) items = section.find_all("p", class_="mb-0") print(items) hrefs = [b["mb-0"] for item in items if (a := items.find("b", class_="mb-0"))] print(hrefs)
注释掉hrefs相关的代码后,我能成功获取到截图里显示的这些元素,但我一直没法提取出里面的Hyvä和Näytönohjaimet这两段文本。试了好几种不同的方法都没搞定,有没有大佬能指点一下,我该怎么从这些元素里拿到想要的数据呀?
备注:内容来源于stack exchange,提问作者Dotres
相关产品推荐
相关产品推荐

