Но кажется, я не могу его найти класс таблицы
Код: Выделить всё
QuantityBulk DiscountAdd to CartBuy 50 + ₱1.00 OffAdd to Cart
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import time
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
service = Service('/usr/local/bin/chromedriver') # Adjust path if necessary
driver = webdriver.Chrome(service=service, options=chrome_options)
def get_page_html(url):
driver.get(url)
time.sleep(3) # Wait for JS to load
return driver.page_source
def scrape_discount_quantity(url):
page_html = get_page_html(url)
soup = BeautifulSoup(page_html, "html.parser")
# Locate the table containing the quantity and discount
table = soup.find('table', class_='hulkapps-table')
print(page_html)
if table:
table_rows = table.find_all('tr')
for row in table_rows:
quantity_cells = row.find_all('td')
if len(quantity_cells) >= 2: # Check if there are at least two cells
quantity_cell = quantity_cells[0].get_text(strip=True) # Get quantity text
discount_cell = quantity_cells[1].get_text(strip=True) # Get discount text
return quantity_cell, discount_cell
return None, None
# Example usage
url = 'https://papemelroti.com/products/live-free-badge'
quantity, discount = scrape_discount_quantity(url)
print(f"Quantity: {quantity}, Discount: {discount}")
driver.quit() # Close the browser when done
Для справки:

Подробнее здесь: https://stackoverflow.com/questions/790 ... tiful-soup