我要在此页面中获得产品名称和价格,请遵循我的代码:
r = requests.get("https://www.paodeacucar.com/produto/67746/")
product_html = parser.fromstring(r.text)
name = product_html.xpath("//h2[@class='hidden-xs hidden-sm ng-binding']/text()") price_str =
product_html.xpath("//p[@class='normal-price ng-binding ng-scope']/text()")
答案 0 :(得分:0)
您将需要Selenium,因为wesbite使用javascript来显示价格。 要使用Selenium选择产品的价格,您将需要类似:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver.get('https://www.paodeacucar.com/produto/67746/')
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//schema[@itemprop='price']"))).get_attribute("content"))