【问题标题】:Extracting data from godaddy using jsoup使用jsoup从godaddy中提取数据
【发布时间】:2018-07-30 00:41:05
【问题描述】:

我正在使用 Jsoup 从 Godaddy 的网站中提取 html。我想在下面提取这个特定的部分。我有最终网页的特定部分,其中显示“抱歉,google.com 已被占用”和 HTML 代码本身。

但是在我的程序中,我有以下内容:

import java.io.IOException;

导入 org.jsoup.Jsoup;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class test {
    public static void main(String[] args) throws IOException {
        String url = "https://www.godaddy.com/dpp/find?checkAvail=1&tmskey=&domainToCheck=google";
        Document document = Jsoup.connect(url).get();
        Element div = document.getElementById("searchResults");
        Elements spans = div.select("span");
        for (Element e: spans)
            System.out.println(e.text());
    }
}

但是,此代码会打印 NullPointerException。我知道 JSoup 不能与 JS 一起使用,但这是 HTML 并且由于某种原因它没有被提取。我还尝试从页面中提取所有 HTML,它不包含这些单词。

谁能指出我正确的方向或给我另一种方法来从 godaddy 提取这条信息?

【问题讨论】:

标签: java html parsing jsoup


【解决方案1】:

首先,您提供的网址重定向到其他位置,因此您需要遵循重定向:

Document document = Jsoup.connect(url).followRedirects(true).get()

但即使这样也不能解决您的问题。为了显示域是否可用,网站使用 javascript 从服务器获取数据。现在此请求将失败,因为它来自未知来源。

总之 Pedro 是对的,你必须使用 API。

【讨论】:

  • 您能否为我指明如何使用此 Godaddy API 的方向?我希望能够将其合并到 Java 中。
  • godaddy 提供了 REST api,因此您已经了解了它们是什么以及如何在 JAVA 中使用它们。 mkyong.com/webservices/jax-rs/…
猜你喜欢
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 2020-10-29
  • 1970-01-01
  • 2012-03-10
  • 2012-03-15
  • 1970-01-01
相关资源
最近更新 更多