“请求购买”价格蒸汽
我想从蒸汽市场获得这个价格,但是如果我尝试以这种方式获得它,
name = "P250 | Red Rock (Battle-Scarred)"
html = requests.get("https://steamcommunity.com/market/listings/730/"+name).text
soup = BeautifulSoup(html,"html5lib")
我只能获得任何价值。另一只手可以使用硒,但对我来说很慢(一个要求将近3秒)。如何获得这个数字?
I want to get this price from steam market but if i try to get it this way
name = "P250 | Red Rock (Battle-Scarred)"
html = requests.get("https://steamcommunity.com/market/listings/730/"+name).text
soup = BeautifulSoup(html,"html5lib")
I only get None value. Another hand I can use Selenium but it's very slow for me (nearly 3 sec in one request). How to get this number ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您一无所获,因为某些JavaScript在网页上动态添加了该价格元素。尝试使用BS4查找具有ID
Market_Commodity_buyrequests
的跨度元素的父元素(包含价格)。您会看到父级DIV元素没有元素,也没有文本。虽然在浏览器中,您会发现两个跨度元素,而休息将是文本节点。那就是问题。使用网络工具,我看到源HTML上的JS提出了以下请求。它使用称为
item_name_id
标识产品的数字ID。如果您可以找到此数字ID,则可以构建URL(返回JSON响应),并使用名为buy_order_summary
的键从响应中获取价格。该密钥的值具有HTML标记,并由您的原始requests.get(url)
响应中缺少的内容组成。这是定价和示例代码获取和使用的URL。
输出:
You are getting None because that price element is dynamically added on the web page by some JavaScript. Try finding parent element of the span element (which contains price) with id
market_commodity_buyrequests
using bs4. You'll see that parent div element has no elements and no text. While in a browser you'll find two span elements and rest would be text nodes. That's the problem.Using network tools I saw that a JS on the source HTML makes the following request. It uses a numeric ID called
item_name_id
to identify the product. If you can find this numeric ID, you can construct the URL (returns JSON response) and get the price from the response using the key namedbuy_order_summary
. This key's value has HTML markup and consists of content that is missing in your originalrequests.get(url)
response.Here's the URL for pricing and sample code to get and use it.
Output: