I want to get the lowest price in steammarket

Issue

[enter image description here][1] I wrote this awful parser to get permanent selling price.

I run it in normal mode in Pycharm but it print "None".
But in Debug mode it returns permanent selling price .

import time
from selenium.webdriver.common.by import By
from selenium import webdriver

def permanent_sale_price(name: str):
    url = "".join(("https://steamcommunity.com/market/listings/730/", name))
    PATH = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe"
    driver = webdriver.Edge(PATH)
    driver.get(url)
    items = driver.find_elements(By.ID, "market_commodity_buyrequests")
    tx = item.text.split(" ")
    price = float(tx[-1][1:])
    return price

def main():
    name = "P250 | Franklin (Field-Tested)"
    print(permanent_sale_price(name))

if __name__ == '__main__':
    main()

"[1]: https://i.stack.imgur.com/Est2D.png permanent selling price ,id in html "market_commodity_buyrequests" "

(P. S. without Loop)

Solution

try this

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def permanent_sale_price(name: str):
    url = "".join(("https://steamcommunity.com/market/listings/730/", name))
    PATH = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe"
    driver = webdriver.Edge(PATH)
    driver.get(url)
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID,  "market_commodity_buyrequests"))
    )
    items = driver.find_elements(By.ID, "market_commodity_buyrequests")
    tx = item.text.split(" ")
    price = float(tx[-1][1:])
    return price

def main():
    name = "P250 | Franklin (Field-Tested)"
    print(permanent_sale_price(name))

if __name__ == '__main__':
    main()

Answered By – federikowsky

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published