Skip to main content
 首页 » 编程设计

python之如何使用 Python 从字符串中提取一些信息

2025年05月04日36pengyingh

我刚开始玩 BeautifulSoup,我想用 Python 创建一些东西,但是当我抓取信息时,标签包含在我不想要的结果中,无论如何我可以分开标签中的产品 ID?

我的结果示例:

<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 
<product-id type="integer">8422899464</product-id> 

请您参考如下方法:

如果你想获取 product-id 的数据,请尝试这样的事情:

data = soup.find('product-id').getText() 
print(data)