chromedriver 不渲染网页抓取数据

问题描述 投票:0回答:1

我正在尝试使用 python 抓取网站数据。

我使用的是selenium版本4.20.0 我的系统中尚未安装 chromedriver。但是我的脚本仅使用 chrome 就运行得很好。

0.91 更新后,当我运行脚本时,我的 chrome 仍然可以工作,但它只是不渲染任何数据。

只有“数据”;继续显示在选项卡以及网址搜索输入框中。

下面是我的代码和数据未渲染的屏幕截图。

import configparser
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException, TimeoutException, StaleElementReferenceException
from openpyxl import load_workbook
import time
import os
import logging

# Get the download path for the current user
config = configparser.ConfigParser()
# Configure logging
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def run_script(config):

    config.read('credentials.ini')
    # Load the workbook
    book  = config ['Credentials']['saveFilePath']
    wb = load_workbook(book)
    ws = wb.active
    # Clear the sheet
    ws.delete_rows(2, ws.max_row)
    # Find the next empty row in the worksheet
    next_row = ws.max_row + 1

    username = config['Credentials']['username']
    password = config['Credentials']['password']
    AgencyFilePath = config['Credentials']['AgencyFilePath']
    workbook = load_workbook(AgencyFilePath)
    sheet = workbook.active

    try: 
        driver = webdriver.Chrome()

        login_url = 'https://www.google.com'
        driver.get(login_url)

        wait = WebDriverWait(driver, 30)

        username_field = wait.until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="lock-title"]'))
        )

        # Find the username and password input fields and submit button by class name
        username_field = driver.find_element(
            By.XPATH, '//*[@id="1-email"]' #xpath of username field
        ).send_keys(username)

        password_field = driver.find_element(
            By.XPATH, '//*[@id="1-password"]' #Xpath of password field
        ).send_keys(password)

问题图片

python google-chrome selenium-webdriver selenium-chromedriver
1个回答
0
投票

在此 StcakOverflow 问题中解决了同样的问题:Python Selenium Chrome Webdriver

如果您的问题仍未解决,请评论我的答案..

© www.soinside.com 2019 - 2024. All rights reserved.