1、安装selenium,pip install selenium
2、下载浏览器驱动,https://pypi.org/project/selenium/,以edge为例,
下载与浏览器对应的版本,https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
3、下载后,解压到c盘即可
1 from selenium import webdriver 2 3 browser = webdriver.Edge(r'C:edgedriver_win64msedgedriver.exe') 4 url =‘https://www.baidu.com’ 5 browser.get(url) 6 print(browser.page_source) 7 browser.close()
4、运行即可打印出源代码