[英]Extracting data from godaddy using jsoup
我正在使用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,但其中不包含這些單詞。
誰能指出我正確的方向,還是給我另一種方法來從哥達迪中提取這條信息?
首先,您提供的網址將重定向到其他位置,因此您需要遵循重定向:
Document document = Jsoup.connect(url).followRedirects(true).get()
但是即使那樣也不能解決您的問題。 為了顯示域是否可用,網站使用javascript從服務器獲取數據。 現在,此請求將失敗,因為它來自未知來源。
簡而言之, Pedro是正確的,您必須使用API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.