Selenium,作为一个Web应用程序测试的工具。
1,配置selenium的路径和浏览器,我用的是firefox
webdriver.firefox.bin=D:/tools/firefox/firefox.exe
webdriver.gecko.driver=D:/project/geckodriver.exe
分别为firefox的安装路径和firefox的驱动路径,这个驱动主要是驱动firefox自动打开,点击按钮等操作。
2,
public class Selenium{ private static String driver = ""; private static String fireFox = ""; static { //读取配置文件中关于Selenium的配置 Properties properties = new Properties(); InputStream in = Object.class.getResourceAsStream("/selenium.properties"); try { properties.load(in); //驱动路径 driver = properties.getProperty("webdriver.gecko.driver"); //浏览器路径 fireFox = properties.getProperty("webdriver.firefox.bin"); } catch (Exception e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } WebDriver webDriverPC = new FirefoxDriver();
public static void main(String[] args) { String content = webDriverPC.get("http://www.baidu.com") } }
这样就可以得到请求后的HTML,在用
Jsoup处理
Document doc = Jsoup.parse(content);
可得到里面的内容。