[Python] Web scraping to capture first listing using python

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to pull through on python estimated sales.

    I have inserted a picture of the inspected code. [![Full element][1]][1]

    This I am trying to pull through on python estimated sales.

    I have inserted a picture of the inspected code.

    This is what I have currently written but it is not pulling through any results. I am unsure how it would locate the first listing as there is multiple <li style="cursor: pointer;" as shown in picture too [![colapsed element][2]][2]

    def fetch_sas_est_sales(driver, sas_url):
    """Fetch estimated sales from SAS for the first product listing."""
    try:
    driver.get(sas_url)
    time.sleep(3) # Allow page to load
    soup = BeautifulSoup(driver.page_source, "html.parser")

    # ✅ Locate the first product listing
    first_product = soup.select_one("li[style='cursor: pointer;']")
    if first_product:
    est_sales_tag = first_product.select_one('.panel-body.qi-estimated-sales-pnl.criteria-info .productList-estimated-sales')
    if est_sales_tag:
    est_sales_match = re.search(r"(\d+)/mo", est_sales_tag.text)
    if est_sales_match:
    return int(est_sales_match.group(1))

    return "N/A"

    except Exception as e:
    print(f"⚠️ Error fetching SAS estimated sales: {e}")
    return "N/A"


    It just pulls through N/A into the discord server for that function.

    Continue reading...

Compartilhe esta Página