htmlunit抓取动态网页(Java编写的代码:之后click(),我的问题)

优采云 发布时间: 2021-09-22 12:15

  htmlunit抓取动态网页(Java编写的代码:之后click(),我的问题)

  htmlUnit是一个伟大的Java库,允许您填写并在编程中提交Web表单。我目前正在保障在ASP中编写的一个相当旧的系统,而不是每月手动填写网络形式,但试图找到一种自动化整个任务的方法,因为我被遗忘了。这是一个表,它检索在一个月内采集的数据。到目前为止,这是我写的代码:

  WebClient client = new WebClient();

HtmlPage page = client.getPage("http://urlOfTheWebsite.com/search.aspx");

HtmlForm form = page.getFormByName("aspnetForm");

HtmlSelect frMonth = form.getSelectByName("ctl00$cphContent$ddlStartMonth");

HtmlSelect frDay = form.getSelectByName("ctl00$cphContent$ddlStartDay");

HtmlSelect frYear = form.getSelectByName("ctl00$cphContent$ddlStartYear");

HtmlSelect toMonth = form.getSelectByName("ctl00$cphContent$ddlEndMonth");

HtmlSelect toDay = form.getSelectByName("ctl00$cphContent$ddlEndDay");

HtmlSelect toYear = form.getSelectByName("ctl00$cphContent$ddlEndYear");

HtmlCheckBoxInput games = form.getInputByName("ctl00$cphContent$chkListLottoGame$0");

HtmlSubmitInput submit = form.getInputByName("ctl00$cphContent$btnSearch");

frMonth.setSelectedAttribute("1", true);

frDay.setSelectedAttribute("1", true);

frYear.setSelectedAttribute("2012", true);

toMonth.setSelectedAttribute("1", true);

toDay.setSelectedAttribute("31", true);

toYear.setSelectedAttribute("2012", true);

games.setChecked(true);

submit.click();

  单击()后,我应该等待确切的页面完成重新加载,因为某些表中有一个表,显示了我的搜索结果。然后,当加载页面时,我需要将其作为HTML文件下载(非常类似于“您喜欢的”浏览器中的页面),因为我将抓住数据来计算总和,我已经使用了JSoup完成了图书馆。

  我的问题是:1.如何制作一个编程方式来完成HTMLUnit的加载? 2.如何将生成的网页编程为编程中的HTML文件?

  我已经研究了HTMLUnit文档,找不到适合我的课程。

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线