Python Beautiful Soup,如何找回 'data-id'
Python Beautiful Soup, how to retrieve the 'data-id'
我想弄清楚如何从某物中提取数据 ID
喜欢
<div class="tweet-text" data-id="1091362563202396165">
dir="ltr" href="h" rel="nofollow noopener" target="_blank" title=.html">cnbc.com/2019/02/01/non…</a>
</div>
我试过 select('.data-id')
也 d.get_text('data-id')
, d.match('data-id')
。我正在尝试提取 data-id
中的实际值,数字...。感谢您的帮助。同时我会继续努力...
您可以使用 attrs={"data-id": True}
的搜索查询来查找具有 data-id
值的元素。
for item in soupdata.find_all(attrs={"data-id": True}):
print (item['data-id'])
我想弄清楚如何从某物中提取数据 ID 喜欢
<div class="tweet-text" data-id="1091362563202396165">
dir="ltr" href="h" rel="nofollow noopener" target="_blank" title=.html">cnbc.com/2019/02/01/non…</a>
</div>
我试过 select('.data-id')
也 d.get_text('data-id')
, d.match('data-id')
。我正在尝试提取 data-id
中的实际值,数字...。感谢您的帮助。同时我会继续努力...
您可以使用 attrs={"data-id": True}
的搜索查询来查找具有 data-id
值的元素。
for item in soupdata.find_all(attrs={"data-id": True}):
print (item['data-id'])