有一个基本的 html 页面,我想对其进行屏幕抓取。我不知道从哪里开始,所以任何帮助将不胜感激。 要访问页面,需要输入一位,就像输入 ID 一样。 所以我想做的是 1.进入网页 2.输入编号 3.然后屏幕抓取(获取数据(我已经检查了所有简单的html的来源))被取消显示 4.剩下的组织(字符串操作)等我可以做。
如果有人能给我一些信息/开始,我将不胜感激:)
最佳答案
这里有一些关于从哪里开始的信息:
第 1 步 - 下载并在您的项目中使用以下 JAR 文件:
- selenium-java-2.xx.0.jar
selenium-server-standalone-2.xx.0.jar
目前
xx
为39。
第 2 步 - 使用以下示例类模拟客户端浏览器以访问网页:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
class MyClass
{
private WebDriver webDriver = null;
public void open() throws Exception
{
webDriver = new FirefoxDriver();
}
public void close() throws Exception
{
webDriver.quit();
}
public void doStuff(String url) throws Exception
{
webDriver.get(url);
// Use 'webDriver' in order to access the web-page, for example:
WebElement inputBox = webDriver.findElement(By.id("someInputBox"));
WebElement inputBtn = webDriver.findElement(By.id("someInputBtn"));
inputBox.sendKeys("myUserId");
inputBtn.click();
String pageSource = webDriver.getPageSource();
...
}
}
关于Java之前如何用小输入屏幕抓取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21802616/