1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 """
5 以下程序亲测在ubuntu16.04下有效,其他环境可能会有错误出现
6 """
7
8 from selenium import webdriver
9 from pyvirtualdisplay import Display
10
11 # 模拟一个虚拟界面
12 display = Display(visible=0, size=(1800,1600))
13 display.start()
14 driver = webdriver.Firefox(executable_path=r‘/home/zhou/soft/geckodriver‘)
15 driver.get("https://my.chsi.com.cn/archive/index.action")
16 print (driver.page_source)
17
18 #--------------------------------------------------------------
19 from selenium import webdriver
20
21 #使用62版本chrome,其他版本可能还会有界面
22 chrome_options = webdriver.ChromeOptions()
23 chrome_options.add_argument(‘--no-sandbox‘)
24 chrome_options.add_argument(‘--headless‘)
25 chrome_options.add_argument(‘--disable-gpu‘)
26
27 # driver = webdriver.Chrome(executable_path=r"C:\soft\chromedriver.exe",chrome_options=chrome_options)
28 driver = webdriver.Chrome(executable_path=r"/home/zhou/soft/chromedriver_linux64/chromedriver",chrome_options=chrome_options)
29
30 driver.get(‘https://account.chsi.com.cn/passport/login?service=https%3A%2F%2Fmy.chsi.com.cn%2Farchive%2Fj_spring_cas_security_check‘)
31
32 page=driver.page_source
33 print(page)
34
35
36 #------------------------------------------------------------------------------------------
37 from selenium import webdriver
38 from pyvirtualdisplay import Display
39
40
41 #模拟一个虚拟界面
42 display = Display(visible=0, size=(800, 600))
43 display.start()
44
45 # driver = webdriver.Chrome(executable_path=r"C:\soft\chromedriver.exe",chrome_options=chrome_options)
46 driver = webdriver.Chrome(executable_path=r"/home/zhou/soft/chromedriver_linux64/chromedriver",)
47
48 driver.get(‘https://account.chsi.com.cn/passport/login?service=https%3A%2F%2Fmy.chsi.com.cn%2Farchive%2Fj_spring_cas_security_check‘)
49 page=driver.page_source
50 print(page)