如何让Java应用程序与网站交互
发布时间:2020-05-26 11:22:07 所属栏目:Java 来源:互联网
导读:我有一个程序从excel文件中获取数据并为用户操作它.但是为了获得excel文件的更新,需要从网站下载.我最初尝试使用机器人类导航到网站,使用用户名和密码登录,然后导航到网站的正确部分,找到“下载excel电子表格”按钮并单击它.但我明白这是一种可怕的方式,它并
|
我有一个程序从excel文件中获取数据并为用户操作它.但是为了获得excel文件的更新,需要从网站下载.我最初尝试使用机器人类导航到网站,使用用户名和密码登录,然后导航到网站的正确部分,找到“下载excel电子表格”按钮并单击它.但我明白这是一种可怕的方式,它并不总是有效.
解决方法如果您确实需要与网站互动,那么selenium / webdriver非常适合您的需求:http://code.google.com/p/selenium/wiki/GettingStarted Google搜索示例: package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example {
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – 可以将注释处理器用于代码生成吗?
- java – Hibernate:如何获取当前在会话中的所有对象的列表
- java – Float vs Double
- Java实现的读取资源文件工具类ResourcesUtil实例【可动态更
- java – xssf如何获取任何字符串
- java操作(DOM、SAX、JDOM、DOM4J)xml方式的四种比较与详解
- java – Tomcat 6没有从WEB-INF / lib加载jar
- java – Spring:异常启动过滤器springSecurityFilterChain
- 在Java中广播UDP数据包的正确和有效方法是什么?
- 基于JDK8总结java中的interrupt
