[英]How to pull some information from a string with Python?
我只是开始玩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)
[i.text for i in soup('product-id')]
出:
['8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464',
'8422899464']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.