标题Selenium+Headless Chrome
注意事项:需要安装相应的chrome驱动,chromedrive.exe,并放到目录C:\Windows\System32下面
示例
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import time
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.cctd.com.cn/datasql.php?data=CCTD%C7%D8%BB%CA%B5%BA%B3%A4%D0%AD%BC%DB%B8%F1&name=CCTD%C7%D8%BB%CA%B5%BA%B3%A4%D0%AD%BC%DB%B8%F1&time=%20where%20DATE_FORMAT(END_DATE,%27%Y-%m-%d%27)%20%3E=%20%272019-03-05%27&draw=1")
wait=WebDriverWait(driver,5)
html=driver.page_source
print(html)
driver.quit()
selenium + Headless Firefox
备注:需要下载firefox 对应版本的驱动,geckodriver.exe,并放到目录C:\Windows\System32下面
示例
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.wait import WebDriverWait
if __name__ == "__main__":
options = Options()
options.add_argument('-headless')
driver = Firefox( options=options)
wait = WebDriverWait(driver,10)
driver.get('https://www.cctd.com.cn/datasql.php?data=CCTD%C7%D8%BB%CA%B5%BA%B3%A4%D0%AD%BC%DB%B8%F1&name=CCTD%C7%D8%BB%CA%B5%BA%B3%A4%D0%AD%BC%DB%B8%F1&time=%20where%20DATE_FORMAT(END_DATE,%27%Y-%m-%d%27)%20%3E=%20%272019-03-05%27&draw=1')
html = driver.page_source
print(html)
driver.quit()