【发布时间】:2021-03-19 11:30:44
【问题描述】:
基本上,我想自动化谷歌搜索引擎,它基本上搜索并单击单击搜索按钮后填充的第一个链接,所以我使用 python 来执行此操作。我可以成功搜索到东西,但页面重新加载后无法点击链接
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
url = "https://www.google.com"
driver = webdriver.Chrome("C:/Users/User/Python/AllCodes/chromedriver.exe")
driver.get(url)
insert = driver.find_element_by_name("q")
insert.send_keys("K.J.Somaiya")
button = driver.find_element_by_name("btnK")
button.submit()
# after this new page reload and link are poluated
linktext = driver.find_element_by_link_text("K. J. Somaiya Institute of Management")
linktext.submit()
这个输入类我使用的名字是q
<input class="gLFyf gsfi" jsaction="paste:puy29d;" maxlength="2048" name="q" type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="" role="combobox" spellcheck="false" title="Search" value="" aria-label="Search" data-ved="0ahUKEwj9qOfEmLzvAhWSj-YKHZUYDngQ39UDCAQ">
This the html code from i target linktext which is K.J.Somaiya Inst.....
【问题讨论】:
-
添加一些 HTML 代码,然后解释 wat 是您的错误代码问题。你想重新加载并在谷歌搜索页面上还是被转移到你搜索的链接?
-
你试过
linktext.click()而不是linktext.submit()吗? -
@GajJulije 我已经在图像文件中发布了 html 代码
-
"C:\Users\User\Python\login.py",第 16 行,在
driver.find_elements_by_class_name("LC20lb DKV0Md").click() AttributeError: 'list' object has没有属性“点击” -
@GajJulije 谢谢,因为这个类是动态变化的,所以我必须要这样一个不会改变的类我明白你的意思
标签: python selenium automation new-operator