Python:Selenium在cli之后挂起Chrome驱动程序

2024-05-08 07:43:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用selenium和chrome驱动程序自动搜索电子商务,从第一个url开始,键入搜索,单击搜索按钮,返回下一个url,就这样。你知道吗

但是点击之后,下一页就不会加载了,我也不知道为什么。你知道吗

代码:


from selenium import webdriver

def open():
    options = webdriver.ChromeOptions()
    options.add_argument("--window-size=1920x1080")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-gpu")

    drive = webdriver.Chrome(options=options)
    url = 'https://www.extra.com.br/'
    drive.get(url)

    busca = drive.find_element_by_id('ctl00_TopBar_PaginaSistemaArea1_ctl05_ctl00_txtBusca')
    busca.send_keys('Informática')

    botao_buscar = drive.find_element_by_id('ctl00_TopBar_PaginaSistemaArea1_ctl05_ctl00_btnOK')
    botao_buscar.click()

    return drive.current_url

if __name__ == '__main__':
    print(open())

我试着直接打开第二个url(不使用表单提交),它可以工作。你知道吗


Tags: addidurlbyseleniumdriveelementopen