【问题标题】:Jsoup to crawle pages to my local driveJsoup 将页面抓取到我的本地驱动器
【发布时间】:2014-03-05 20:00:38
【问题描述】:

我正在研究一个搜索引擎,我想要一个 jsoup 网络爬虫来从网站获取页面并将这些页面存储在我的本地硬盘驱动器中,例如 C:\tmp。你能帮我解决这个问题吗

谢谢 ;)

【问题讨论】:

  • 为什么要使用 Jsoup?将网页下载为 HTML 文件并存储在您想要的位置?
  • 是的,但我不想手动操作,我希望 jsoup 一次从一个网站下载页面

标签: html search download jsoup web-crawler


【解决方案1】:

你可以用jsoup试试这个。

    try {
        Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Main_Page").get();
        String html = doc.html();
        BufferedWriter out = new BufferedWriter(new FileWriter("c:/tmp/wiki.html"));
        out.write(html);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

它将生成一个名为wiki.html 的文件,其中包含目录c:/tmp/ 中的维基百科主页。

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 2018-06-03
    • 2013-01-02
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 2021-06-28
    相关资源
    最近更新 更多