Get inspect link from Item on Steam Community Market

Viewed 4819

Using the link below i want to find the inspect link for every listed item on the page, preferably using Python. https://steamcommunity.com/market/listings/730/AK-47%20%7C%20Redline%20%28Field-Tested%29

The inspect link is located in the href of this element: <a class="popup_menu_item" href="steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M3278013081425287850A19320993972D11848058731724408597">Inspect in Game...</a>

The problem i'm facing is that the inspect link is only created and populated if we press on this element for every listing: <a id="listing_3278013081425287850_actionmenu_button" class="market_actionmenu_button" href="javascript:void(0)"></a>

this is my current code:

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")

but because the html item doesn't exist i can't find anything. a = []

how can i populate the html item and read it's href value? Do i need to use something like selenium or is this possible with requests?

1 Answers

Got it working using selenium as suggested in the comments.

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)
Related