我有一个程序从excel文件中获取数据并为用户操作它.但是为了获得excel文件的更新,需要从网站下载.我最初尝试使用机器人类导航到网站,使用用户名和密码登录,然后导航到网站的正确部分,找到"下载excel电子表格"按钮并单击它.但我明白这是一种可怕的方式,它并不总是有效.有什么更好的方法我可以这样做,以便我的程序可以访问网站并导航到我想要的页面,然后下载数据.我读到了关于"页面报废"的内容,但我认为不会允许我这样做.我真的想与网页互动,而不是下载它的内容.任何帮助都会很棒.谢谢,彼得
Pab*_*jim 13
如果您确实需要与网站互动,那么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());
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33129 次 |
| 最近记录: |