小编Las*_*oth的帖子

如何在python中用漂亮的汤从div中find_all(id)

我想从具有唯一类的页面中打印出所有 ID。

我想用 Beautiful Soup 抓取的页面是这样的:

<div itemscope itemprop="item" itemtype="http://schema.org/Product" id="12345" class="realestate"> 
<div class="contentArea"> 
<meta itemprop="name" content="Name - 12345 " /> 
<meta itemprop="url" content="https://url12345.hu" />   
<meta itemprop="category" content="category1" />   
</div>
</div>
<div itemscope itemprop="item" itemtype="http://schema.org/Product" id="12346" class="realestate"> 
<div class="contentArea"> 
<meta itemprop="name" content="Name - 12346 " /> 
<meta itemprop="url" content="https://url12346.hu" />   
<meta itemprop="category" content="category1" />   
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

“ID”是来自 Itemscope DIV 的唯一标识符,所以我想以某种方式提取这些唯一 ID 并将它们全部打印出来(原因是将所有其他广告信息附加到此 ID(例如名称、URL 等)之后)

我尝试使用此 python 代码,但它不起作用。

import requests
from bs4 import BeautifulSoup

page = requests.get('searchResultPage.url')
soup = BeautifulSoup(page.text, 'html.parser') …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup

5
推荐指数
1
解决办法
5721
查看次数

标签 统计

beautifulsoup ×1

python ×1