# coding=utf-8 from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities if __name__=="__main__": url = "http://XXX.XXXXX.com/XX.html" dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ") obj = webdriver.PhantomJS(executable_path=r'D:phantomjsinphantomjs.exe',desired_capabilities=dcap) obj.get(url) html = obj.page_source obj.quit() fw = open("D:\test.html","w",encoding='utf-8') fw.write(html) fw.close() # cx = sqlite3.connect("D:SQLitechuangbing.db") # cx.execute("insert into page_html (page_time,page_url,page_resource) values (datetime('now'),?,?)",(url,html)) # cx.commit() # cx.close()