admin管理员组

文章数量:1291675

I am trying to pull through on python estimated sales.

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

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.

UPDATE *****

The site required log in so I have used selenium to log in which when the script runs, it says successful log in.

in the debug it also pulls through the first and last characters of the code to see if it is detecting anything.

from selenium.webdrivermon.by import By 
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from seleniummon.exceptions import TimeoutException, NoSuchElementException
import time

def fetch_sas_est_sales(driver, sas_url):
    """Fetch estimated sales from SAS by specifically targeting 
    <div class="panel-body qi-estimated-sales-pnl criteria-info"> and its span."""
    
    try:
        driver.get(sas_url)

        # Wait for page to load
        WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
        print("✅ Page loaded. Now scrolling...")

        # 

本文标签: selenium webdriverWeb scraping to capture first listing using pythonStack Overflow