Python例子

windows安装selenium获取页面代码

在我们的python工作中,经常需要用到selenium,本文为大家介绍windows安装selenium获取页面代码。

#从selenium里面导入webdriver
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
#指定chrom的驱动
#执行到这里的时候Selenium会到指定的路径将chrome driver程序运行起来
driver = webdriver.Chrome('E:\www\zufang\sele\chromedriver.exe',options=options)

#get 方法 打开指定网址
driver.get('https://www.baidu.com/')
code = driver.page_source
print(code)

code就是获取到的百度的源代码

最后修改:2021-08-19 11:02:21