[英]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.