浏览器爬虫入门:Python+Selenium+ChromeDriver 「爱情、让人受尽委屈。」 2021-11-23 12:10 310阅读 0赞 **下载对应版本的chromedriver.exe: [http://chromedriver.storage.googleapis.com/index.html][http_chromedriver.storage.googleapis.com_index.html]** **下载后将chromedriver.exe放到python安装目录或其下的Scripts目录下,就可以正常调用。** from selenium import webdriver import os driver = webdriver.Chrome() driver.maximize_window() # chrome窗口最大化 driver.get('http://www.baidu.com') driver.close() # 关闭driver(关闭当前窗口) os.system('taskkill /f /im chromedriver.exe') # 关闭chromedriver.exe进程 #如果pycharm执行os.system操作产生乱码: # File > Settings > Editor > File Encodings,将Global Encoding改成GBK即可。 from selenium import webdriver#下面3行代码执行后,不会打开Chrome浏览器,不会产生chromedriver.exe进程 options = webdriver.ChromeOptions() options.add_argument('headless') driver = webdriver.Chrome(chrome_options=options) driver.get('http://www.baidu.com') print(driver.title) #获取打开网址的标题 driver.find_element_by_id('kw').send_keys('博客园') #百度搜索'博客园' driver.quit() # 关闭driver(关闭窗口并结束chromedriver.exe进程) **driver.close()和driver.quit()的区别:[https://blog.csdn.net/huilan\_same/article/details/52329804][https_blog.csdn.net_huilan_same_article_details_52329804]** 转载于:https://www.cnblogs.com/cloak/p/11218754.html [http_chromedriver.storage.googleapis.com_index.html]: http://chromedriver.storage.googleapis.com/index.html [https_blog.csdn.net_huilan_same_article_details_52329804]: https://blog.csdn.net/huilan_same/article/details/52329804
还没有评论,来说两句吧...