Javascript 如何在java中使用web scraper获取内容

Javascript 如何在java中使用web scraper获取内容,javascript,web-scraping,jsoup,Javascript,Web Scraping,Jsoup,需要您的帮助以java/J2EE构建一个可以作为Web刮板的应用程序 以下是我对这个项目的看法 在我的应用程序主页中将有一个文本框,用户可以在其中输入他们想要访问的任何URL。 点击go按钮后,网页将显示在我的应用程序下,即URL将与我的应用程序保持相同。 用户可以在网页的文本框中输入任何内容,然后单击相应的操作(搜索/提交)。 在该页面的表单提交中,我可以捕获用户放在文本框中的文本,并将其保存在我的数据库中。 就这样 现在的问题是,如果我看一些已经可用的基于java的Web scraper,比

需要您的帮助以java/J2EE构建一个可以作为Web刮板的应用程序

以下是我对这个项目的看法

在我的应用程序主页中将有一个文本框,用户可以在其中输入他们想要访问的任何URL。 点击go按钮后,网页将显示在我的应用程序下,即URL将与我的应用程序保持相同。 用户可以在网页的文本框中输入任何内容,然后单击相应的操作(搜索/提交)。 在该页面的表单提交中,我可以捕获用户放在文本框中的文本,并将其保存在我的数据库中。 就这样

现在的问题是,如果我看一些已经可用的基于java的Web scraper,比如WebHarvest,它们只是捕获URL上的预定义字符串

请帮助我找到一些教程或任何开源应用程序,可以为我工作后,一些修改

任何帮助都将不胜感激


谢谢。

我将为您提供简单的Java版Selenium WebDriver。然而,你可能会发现所有的细节


还有一些关于Java的。

我将为您提供简单的Java中的Selenium WebDriver。然而,你可能会发现所有的细节

还有一些关于Java的

import java.io.*;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebScraper {

    public WebDriver driver = new FirefoxDriver();

    /**
     * Open the test website.
     */
    public void openTestSite() {
        driver.navigate().to("http://testing-ground.scraping.pro/login");
    }

    /**
     * 
     * @param username
     * @param Password
     * 
     *            Logins into the website, by entering provided username and
     *            password
     */
    public void login(String username, String Password) {

        WebElement userName_editbox = driver.findElement(By.id("usr"));
        WebElement password_editbox = driver.findElement(By.id("pwd"));
        WebElement submit_button = driver.findElement(By.xpath("//input[@value='Login']"));

        userName_editbox.sendKeys(username);
        password_editbox.sendKeys(Password);
        submit_button.click();

    }

    /**
     * grabs the status text and saves that into status.txt file
     * 
     * @throws IOException
     */
    public void getText() throws IOException {
        String text = driver.findElement(By.xpath("//div[@id='case_login']/h3")).getText();
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("status.txt"), "utf-8"));
        writer.write(text);
        writer.close();

    }

    /**
     * Saves the screenshot
     * 
     * @throws IOException
     */
    public void saveScreenshot() throws IOException {
        File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("screenshot.png"));
    }

    public void closeBrowser() {
        driver.close();
    }

    public static void main(String[] args) throws IOException {
        WebScraper webSrcaper = new WebScraper();
        webSrcaper.openTestSite();
        webSrcaper.login("admin", "12345");
        webSrcaper.getText();
        webSrcaper.saveScreenshot();
        webSrcaper.closeBrowser();
    }
}