首页 > 解决方案 > Selenium 无法加载内容(python)

问题描述

所以我试图从这个 URL 获取一些数据,

https://supermercado.carrefour.com.ar/leche-fluida-infantil-nutrilon-etapa-1-200-cc/p

我在 chromedriver 中使用 selenium,我面临的问题是,当我在浏览器中打开链接时,它会加载所有内容,一切正常,但是当我对 chromedriver 执行相同操作时,它有时会加载内容,有时它只是没有' t 加载我不理解的内容,因为 chromedriver 应该像普通浏览器一样运行,有人可以帮我弄清楚这里发生了什么,

这是我的一些代码,

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--window-size=1920,1080")

capabilities = DesiredCapabilities.CHROME.copy()
capabilities['acceptSslCerts'] = True
capabilities['acceptInsecureCerts'] = True
capabilities['platform'] = "WINDOWS"
capabilities['version'] = "10"

driver = webdriver.Chrome(options=chrome_options,
                          desired_capabilities=capabilities,
                          executable_path=r'C:\Program Files\chromedriver.exe')
url = 'https://supermercado.carrefour.com.ar/leche-fluida-infantil-nutrilon-etapa-1-200-cc/p'
driver.get(url)

time.sleep(10)

title = driver.find_element_by_xpath('//meta[@property="og:title"]').get_attribute('content')
sku = driver.find_element_by_xpath('//meta[@property="product:sku"]').get_attribute('content')
brand = driver.find_element_by_xpath('//meta[@property="product:brand"]').get_attribute('content')
r_id = driver.find_element_by_xpath('//meta[@property="product:retailer_item_id"]').get_attribute('content')
price = driver.find_element_by_xpath('//meta[@property="product:price:amount"]').get_attribute('content')

driver.quit()

标签: pythonseleniumautomationscreen-scraping

解决方案


推荐阅读