You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:13:06