簡體   English   中英

jsoup-搜索表單的URL在post()中未更改

[英]jsoup- Search Form's URL not changing in post()

我正在開發網絡爬蟲。 我需要在表單的輸入字段中插入一些值(用於搜索),並以編程方式獲取結果。 表單具有post方法,並且操作值為"/SetReviewFilter#REVIEWS"
但是問題是,當我手動從網站進行搜索時,網站的URL不會更改。
我認為該網頁是自發布的, 此處是該網頁的鏈接

我不知道如何實現這個。但是我嘗試了這個

private Document getReviewSearchDocument(Document search,String search_url)
    {
//search_url mean the url of that search document I fetched previously
// search means the current document of the webpage

    Element input = search.getElementsByClass("ratings_and_types").first();
        Element link = input.select("div:nth-child(1) > form ").first();
        Document rdocument= null;

        if (link !=null) {
            System.out.println("form found! on: "+link_value);
        } else {
            System.out.println("Form not found");
        }
        Connection connection = Jsoup.connect(search_url + "/SetReviewFilter#REVIEWS").timeout(30 * 1000).ignoreContentType(true).ignoreHttpErrors(true);
        try {
            Connection.Response resp = connection.execute();

            if (resp.statusCode() ==200) {

                rdocument = connection.data("q",this.keywords).userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36").execute().parse();
                System.out.println("Success: "+ resp.statusCode());
                System.out.println("document: "+ rdocument.text().toString());
            }
            else{
                System.out.println("no search match");
            }



        } catch (IOException e) {
            e.printStackTrace();
        }




        return rdocument;
    }

如果有人對此有想法,請分享。
謝謝。

我嘗試了幾種方法並修改了代碼以調用JSOUP POST請求以完成工作,但是由於cookie的問題,我幾次失敗了。我發現,對於這個單個post請求,它幾乎需要50個cookie(感謝Chrome控制台)。有些cookie我無法自己填寫,因為這些cookie鏈接到了不同的網站(例如:facebook)。最糟糕的情況是,我必須根據每個城市的酒店數量提出此請求。因此有時可能會高達85 000,所以這將是一個昂貴的過程。(-5對我來說是沒有看到的到來)

在那里,我使用Java中的Selenium通過Web Automation通過Web Automation重建了項目,並且表單搜索變得如此簡單。
謝謝!

暫無
暫無

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

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