Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jsoup返回状态400_Java_Web Crawler_Jsoup - Fatal编程技术网

Java Jsoup返回状态400

Java Jsoup返回状态400,java,web-crawler,jsoup,Java,Web Crawler,Jsoup,我要从此URL抓取数据: 因此,我编写了以下代码 import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import static org.jsoup.Connection.*; /** * Created by avi on 11/24/17. */ public class ExpediaCurl { public static void main(String

我要从此URL抓取数据:

因此,我编写了以下代码

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import static org.jsoup.Connection.*;

/**
 * Created by avi on 11/24/17.
 */
public class ExpediaCurl {

    public static void main(String[] args) {
        final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";


        Response res = null;
        try {
            res = Jsoup.connect("http://www.expedia.co.jp/Osaka-Hotels-Hotel-Consort.h5522663.Hotel-Information?")
                    .data("adults", "2", "children", "0",  "chkin", "2017/12/13", "chkout", "2017/12/14")
                    .method(Method.POST)
                    .execute();

            Document doc = res.parse();
            Map<String,String> cookies = res.cookies();
            System.out.println(cookies.toString());
            Document doc2 = Jsoup.connect("https://www.expedia.co.jp/infosite-api/5522663/getOffers?clientid=KLOUD-HIWPROXY&token=bc9e0d07b9dcc14506a3ce5587703329a02e9f9e&brandId=0&countryId=0&isVip=false&chid=&partnerName=&partnerPrice=0&partnerCurrency=&partnerTimestamp=0&adults=2&children=0&chkin=2017%2F12%2F13&chkout=2017%2F12%2F14&swpToggleOn=false&daysInFuture=&stayLength=&ts=1513141494203&evalMODExp=true&tla=OSA")
                    .cookies(cookies) // <-- I believe This cookie is not working
                    .userAgent(USER_AGENT)
                    .get();
            System.out.printf(doc2.html());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
有人能帮我找出我做错了什么吗

尝试使用

字符串url=http://www.expedia.co.jp/ +
URLEcoder.encodeOsaka Hotels Hotel Consort.h552263.Hotel Information?,UTF-8

您首先声明的URL是GET,但在您的代码中,第二个URL需要cookie,因此我必须使用第一个Jsoup POST方法获取该URL。我猜可能是我使用了错误的cookie id。但我无法找到正确的URL。是的,需要将URL拆分为基本URLhttp://www.expedia.co.jp/ 还有其他的。然后是URLEncoder.encode。。剩下的url,最后合并它们。
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=400, URL=https://www.expedia.co.jp/infosite-api/5522663/getOffers?clientid=KLOUD-HIWPROXY&token=bc9e0d07b9dcc14506a3ce5587703329a02e9f9e&brandId=0&countryId=0&isVip=false&chid=&partnerName=&partnerPrice=0&partnerCurrency=&partnerTimestamp=0&adults=2&children=0&chkin=2017%252F12%252F13&chkout=2017%252F12%252F14&swpToggleOn=false&daysInFuture=&stayLength=&ts=1513141494203&evalMODExp=true&tla=OSA
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:679)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:628)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:260)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:249)
    at ExpediaCurl.main(ExpediaCurl.java:31)