我是python和selenium的新手,真的很喜欢学习。
只是将我的脚趾浸入硒中,并且在使这个脚本工作时遇到一些麻烦。
它没有给出错误它只是打开浏览器并且什么都不做。
{{1}}
答案 0 :(得分:0)
以下是您的问题的答案:
使用Selenium
3.4.3,geckodriver
v0.17.0,Mozilla Firefox
53.0通过Python 3.6.1;由于您一直在尝试从driver.find_element_by_class_name("_Rm")
创建列表并打印列表项,因此我假设您要使用WebElements
来打印链接,而不是https://pypi.python.org/pypi/selenium
等。这是您自己的代码块,其中包含一些简单的调整,您可以使用它们来实现以下目标:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
kw = input("Provide the keyword to search through google : ")
# creates firefox session
driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.implicitly_wait(30)
# navigate to google
driver.get("http://www.google.com")
#get the search textfield
search_field = driver.find_element_by_id("lst-ib")
search_field.clear()
#enter search kw and submit
search_field.send_keys(kw)
search_field.submit()
lists = driver.find_elements_by_class_name("_Rm")
print ("Elements found : {}".format(len(lists)))
i=0
print("Here are the links : ")
for listitem in lists:
print(listitem.get_attribute("innerHTML"))
i=i+1
if(i>10):
break
driver.quit()
控制台上的输出如下:
Provide the keyword to search through google : Selenium
Elements found : 11
Here are the links :
https://en.wikipedia.org/wiki/Selenium_(software)
www.seleniumhq.org/
www.guru99.com/selenium-tutorial.html
https://en.wikipedia.org/wiki/Selenium_(software)
toolsqa.com/selenium-tutorial/
selenium-python.readthedocs.io/
selenium-python.readthedocs.io/getting-started.html
https://github.com/SeleniumHQ/selenium
https://github.com/SeleniumHQ
https://www.pluralsight.com/courses/selenium
www.scalatest.org/user_guide/using_selenium
如果这回答你的问题,请告诉我。