簡體   English   中英

Jsoup元刷新重定向

[英]Jsoup meta refresh redirect

我想從元刷新重定向獲取HTML頁面,就像jsoup可以處理元刷新重定向一樣

但是我無法正常工作。 我想在http://synchronkartei.de上進行搜索。 我有以下代碼:

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

public class SynchronkarteiScraper {
  public static void main(String[] args) throws Exception{
    Document doc = Jsoup.connect("https://www.synchronkartei.de/search.php")
                                        .data("cat", "2")
                                        .data("search", "Thomas Danneberg")
                                        .data("action", "search")
                                        .followRedirects(true)
                                        .get();
    Elements meta = doc.select("html head meta");                                  
    for (final Element m : meta){
      if (m.attr("http-equiv").contains("refresh")){
        doc = Jsoup.connect(m.baseUri()+m.attr("content").split("=")[1]).get();
      }
    }

    System.out.println(doc.body().toString());
  }
}

進行搜索,從而導致刷新的臨時站點打開了實際結果頁面。 與轉到http://synchronkartei.de相同,從下拉框中選擇“ Sprecher”,在文本字段中輸入“ Thomas Danneberg”,然后按Enter。

但是即使提取了刷新URL並進行了第二次連接,我仍然可以獲得臨時登錄頁面的內容,該內容可以在正文中看到。

那么,這里出了什么問題?

請注意,站點syncnkartei.de始終重定向到HTTPS。 由於它使用的是StartCom的證書,因此Java抱怨證書路徑。 要使上述代碼段起作用,必須將VM參數-Djavax.net.ssl.trustStore=<path-to-keystore>與正確的證書一起使用。

我不得不承認,我不是Jsoup的專家,但是我知道有關Synchronkartei的一些細節。

Deutsche Synchronkartei支持OpenSearchDescriptions,該鏈接鏈接到/search.xml。 也就是說,您還可以使用https://www.synchronkartei.de/search.php?search={searchTerms}將搜索字詞添加到會話中。

您只需要一個帶有會話ID的cookie“ sid”,Synchronkartei即可為您提供。 之后,直接發送至https://www.synchronkartei.de/index.php?action=search請求將為您提供結果,而不管您的推薦人如何。

我的意思是,首先將請求發送到https://www.synchronkartei.de/search.php?search={searchTerms}https://www.synchronkartei.de/search.php?cat={Category}&search={searchTerms}&action=search (如上所述),如果HTTP結果為200,但完全忽略了會話cookie,則完全忽略該結果。 之后,您向https://www.synchronkartei.de/index.php?action=search發出請求,然后該請求將為您提供整個結果列表。

豐子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM