Selenium, 作为一个 web 应用程序测试的工具.
1, 配置 selenium 的路径和浏览器, 我用的是 firefox
- webdriver.firefox.bin=D:/tools/firefox/firefox.exe
- webdriver.gecko.driver=D:/project/geckodriver.exe
- selenium.properties
分别为 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);
可得到里面的内容.
来源: http://www.bubuko.com/infodetail-2650024.html