python - 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()
解决方案
推荐阅读
- angular - 在 Angular 中关闭浏览器选项卡时如何清除会话存储?
- sql - 如何为每个 id 选择前 2 个值
- flutter-dependencies - 我可以在颤振中编辑插件吗?
- apache-beam - 解码器中的 Apache Beam IOException
- powershell - 通过 Azure RM powershell 获取 API 产品列表
- python - GitPython:在本地和远程删除多个标签
- python - python中导入模块的方法
- javascript - 如何获取所选日期的值
- c++ - wxFrame 缺少最大化按钮
- javascript - 将 REST API 响应重定向到 UI/浏览器 NodeJs/Express/Request