本文介绍了Jsoup返回状态400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要从以下URL抓取数据: http://www.expedia.co.jp/大阪-饭店-饭店-Consort.h5522663.Hotel-Information?chkin = 2017/12/13& chkout = 2017/12/14& rm1 = a2
I want to crawl data from this URL : http://www.expedia.co.jp/Osaka-Hotels-Hotel-Consort.h5522663.Hotel-Information?chkin=2017/12/13&chkout=2017/12/14&rm1=a2
所以我写了以下代码
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();
}
}
}
我遇到以下错误
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)
有人可以帮我解决我在做什么错.
Can someone Help me out that what is wrong I am doing.
推荐答案
尝试使用
String url = "http://www.expedia.co.jp/" +URLEncoder.encode(Osaka-Hotels-Hotel-Consort.h5522663.Hotel-Information?", "UTF-8")
String url = "http://www.expedia.co.jp/" +URLEncoder.encode(Osaka-Hotels-Hotel-Consort.h5522663.Hotel-Information?", "UTF-8")
这篇关于Jsoup返回状态400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!