我正在尝试为我的学校网站制作网络抓取工具。这将输入我的用户名和密码,然后单击登录按钮。有时它可以工作,但否则会给出错误消息。我学校的网站上有两个页面,分别是登录页面和主页。我只是进入了主页的链接,如果是问题的话,请输入idk。这是代码:
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("anonymous")
search1 = driver.find_element_by_id('username')
search1.send_keys('*********')
search2 = driver.find_element_by_id('pwd')
search2.send_keys('******')
submitbutton = driver.find_element_by_xpath('anonymous_x_path')
submitbutton.click()
错误是:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="username"]"}
raise exception_class(message, screen, stacktrace)
self.error_handler.check_response(response)
return self.execute(Command.FIND_ELEMENT, {
return self.find_element(by=By.ID, value=id_)
search1 = driver.find_element_by_id('username')