本文介绍了从强标签抓取网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..如何从强标签中提取数据?
How do i pull the data from the strong tag?
HTML code:
<div class="store-views"><span class="caption">VISIT COUNT</span><br><strong>336</strong></div>
我尝试过soup.find(strong")和soup.find(div", class_=store-views"),但它要么提供了错误的数据,要么提供了无">
I have tried soup.find("strong") and soup.find("div", class_="store-views") but it either comes up with the wrong data or "None"
推荐答案
该值是动态添加的,可能来自谷歌分析.您可以使用 selenium 自动化浏览器,以便在添加时捕获此值:
That value is dynamically added, possibly from google analytics. You can use selenium to automate browser so you can capture this value when added:
from selenium import webdriver
d = webdriver.Chrome()
d.get('https://store.bricklink/legoseller9997&utm_content=globalnav#/shop')
print(d.find_element_by_css_selector('.store-views strong').text)
d.quit()
其他数据来自ajax请求:
The other data comes from an ajax request:
import requests
r = requests.get('https://store.bricklink/ajax/clone/store/searchitems.ajax?showHomeItems=1&sid=1663355', headers= {'User-Agent':'Mozilla/5.0'}).json()
print(r)
这篇关于从强标签抓取网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论