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
版权声明:本文标题:selenium webdriver - Web scraping to capture first listing using python - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1741536673a2384065.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论