【问题标题】:Get inspect link from Item on Steam Community Market从 Steam 社区市场上的 Item 获取检查链接
【发布时间】:2020-09-03 11:17:04
【问题描述】:

使用下面的链接,我想找到页面上每个列出的项目的检查链接,最好使用 Python。 https://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29

inspect 链接位于此元素的href<a class="popup_menu_item" href="steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M3278013081425287850A19320993972D11848058731724408597">Inspect in Game...</a>

我面临的问题是,仅当我们为每个列表按下此元素时,才会创建和填充检查链接: <a id="listing_3278013081425287850_actionmenu_button" class="market_actionmenu_button" href="javascript:void(0)"></a>

这是我当前的代码:

import requests
from bs4 import BeautifulSoup

baseurl = "https://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29"
site = requests.get(baseurl)
soup = BeautifulSoup(site.content, 'html.parser')
a = soup.select("#market_action_popup_itemactions > a")

但是因为 html 项目不存在,所以我找不到任何东西。 a = []

如何填充 html 项并读取它的 href 值? 我是否需要使用 selenium 之类的东西,或者这可以通过请求来实现吗?

【问题讨论】:

  • 我推荐在 Steam 市场上使用 Selenium。
  • 其实每个动态网站都应该使用 Selenium

标签: python-3.x web-scraping beautifulsoup request steam


【解决方案1】:

按照 cmets 中的建议使用 selenium 使其工作。

baseurl = "https://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29"
driver.get(baseurl)
btns = driver.find_elements_by_class_name("market_actionmenu_button")
for btn in btns:
    driver.execute_script("arguments[0].click();", btn)
    popup = driver.find_element_by_css_selector("#market_action_popup_itemactions > a")
    href = popup.get_attribute('href')
    print(href)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2021-08-30
    • 2014-05-28
    相关资源
    最近更新 更多