python - 在网络抓取中获得“无”
问题描述
我对 python 很陌生,但我正在尝试使用 BeautifulSoup 来收集 CSGO 皮肤的价格(特别是出售)。但是,我没有。我怀疑是因为两行 HTML 代码相同,但一个数字是请求,另一个数字是我需要的数字:销售号。有人可以帮忙吗?我特别关注新的挑战者胶囊。如果有人可以提供帮助,那将不胜感激。
import requests
from bs4 import BeautifulSoup
URLChallengerCapsule = 'https://steamcommunity.com/market/listings/730/2020%20RMR%20Challengers'
page = requests.get(URLChallengerCapsule)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find(id='market_commodity_buyrequests')
ChallengerCapsulePrice = results.find('span', class_= 'market_commodity_orders_header_promote')
print(ChallengerCapsulePrice)
import requests
from bs4 import BeautifulSoup
URLChallengerCapsule = 'https://steamcommunity.com/market/listings/730/2020%20RMR%20Challengers'
page = requests.get(URLChallengerCapsule)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find(id='market_commodity_buyrequests')
ChallengerCapsulePrice = results.find('span', class_= 'market_commodity_orders_header_promote')
print(ChallengerCapsulePrice)
解决方案
BeautifulSoup 不适用于使用 JavaScript 同步填充的数据。
当您使用 cURL 加载此页面时(不支持 JavaScript),您可以看到这div
是空的:
curl -s https://steamcommunity.com/market/listings/730/2020%20RMR%20Challengers | grep market_commodity_buyrequests -A 1
<div class="market_commodity_order_summary" id="market_commodity_buyrequests">
</div>
这里有一个很好的无头浏览器列表。你可以在 Python 中找到一些支持 Javascript 的。其他一些在线列表可能是最新的。
推荐阅读
- ios - 如何在 FirebaseUI 中打开自定义电话身份验证视图控制器?
- python - 如何生成一定长度的带前缀的信用卡号?
- python-3.x - 谷歌登录在没有无头但没有无头模式的情况下工作
- c++ - 带有可移动构造元素的 std::tuple 默认构造函数
- clojure - 如何计算包含 NaN 的序列的频率?
- mesh - 使用 CGAL Delaunay3D 自定义 Delaunay 细化
- pycharm - PyCharm如何关闭内联变量资源管理器
- amazon-web-services - 创建 AWS/IAM 策略时获取“策略未能通过旧版解析”
- snowflake-cloud-data-platform - 预先知道 RESULT_SCAN 的所有可能结果?
- javascript - 如何将 amcharts 4 用于与教程略有不同的多组和堆积柱形图