从 Steam 社区市场上的物品获取检查链接
·
问题:从 Steam 社区市场上的物品获取检查链接
使用下面的链接,我想找到页面上每个列出的项目的检查链接,最好使用 Python。https://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29
检查链接位于此元素的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 之类的东西,或者这可以通过请求来实现吗?
解答
按照评论中的建议使用硒工作。
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)
更多推荐
所有评论(0)