Home > Enterprise >  I want to get the lowest price in steammarket
I want to get the lowest price in steammarket

Time:07-05

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

CodePudding user response:

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