我已经下载了最新的python版本(3.8.5(和谷歌chrome版本(84(以及相应的chromedriver版本(84。但是浏览器在运行程序时没有响应。
from time import sleep
from selenium import webdriver
class Bot:
def __int__(self):
self.driver = webdriver.Chrome("C:\Windows\chromedriver.exe")
self.driver.get("www.google.com")
my_bot = Bot()
def main():
my_bot()
if __name__ == 'main':
main()
以上是我的python代码
from time import sleep
from selenium import webdriver
class Bot:
def __init__(self, url):
# path to chrome driver in your local machine
driver_path = "C:\Windows\chromedriver.exe"
# Loading the chrome driver
self.driver = webdriver.Chrome(driver_path)
# Using the above-loaded WebDriver to open the URL in the chrome
# browser
self.driver.get(url)
def main():
# Creating a object of Bot class with URL as an input parameter
# Don't forget to use https:// else your URL won't get open
my_bot = Bot(url="https://www.google.com")
# A sleep timer of 10 sec to let webdriver load the given URL and `
# display it to you for 10 sec
sleep(10)
# Closing the bot object which we created
# After 10 sec the bot object will be closed
my_bot.close()
if __name__ == '__main__':
# Calling the main function where the Bot object is created
main()
三行操作更简单!!
from selenium import webdriver
driver = webdriver.Chrome("G:\Downloads\chromedriver_win32\chromedriver.exe")
driver.get('https://www.google.com/')
你完了!