从强标签抓取网页

编程入门 行业动态 更新时间:2024-10-10 10:29:42
本文介绍了从强标签抓取网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 10:28:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!