When trying to write a daily routine check script to the company's website, you don't need to open the browser, which is the use of Htmlunit
Htmlunit is based on the selenium server, so it needs Selenium-server-standalone-xxx.jar
1. Download and install Java in order to run the jar package
2, download Selenium-server-standalone-xxx.jar, here to pay special attention to the version, to match their own selenium version
To view the methods of the packages that you have installed, cmd commands go to scripts in the directory where Python is installed
Enter the PIP list to see the version number of all installed packages
3, after the completion of the two steps, cmd into the Selenium-server-standalone-xxx.jar installation directory,
cmd command input Java-jar Selenium-server-standalone-xxx.jar, the proxy server is running.
PS: If it fails to start, it may be that the port is occupied, can download TCPView view all ports
4, the last step is to test the htmlunit can be used normally
from Import desiredcapabilities from Import = Webdriver. Remote (desired_capabilities=desiredcapabilities.htmlunit) htmlunit.get ("http/ www.baidu.com")
Print Htmlunit.title
Output Result:
C:\Python27\python.exe f:/soft_test/python/code/htmlunit_test.py Baidu A bit, you know process finished with exit code 0
Selenium + Python test environment to build extended-htmlunit use