在使用用户名和密码发送POST请求后,如何使用Jsoup保存cookie?或者我必须首先将它们提供给连接对象然后保存?
我现在被困在这个问题好几天了,我的眼睛开始受到尝试不同组合的时间的伤害,但没有成功.问题是,我正在制作一个应用程序,它必须从互联网上获取数据,解析它然后显示给用户.我已经尝试了几种方法,并且使用JSOUP非常有帮助,特别是在解析和从结果中获取数据时.
但是,有一个问题我无法解决.我已尝试使用常规HTTPClient和JSOUP,但我无法成功获取所需的数据.这是我的代码(JSOUP版本):
public void bht_ht(Context c, int pozivni, int broj) throws IOException {
//this is the first connection, to get the cookies (I have tried the version without this method separate, but it's the same
Connection.Response resCookie = Jsoup.connect("http://www.bhtelecom.ba/imenik_telefon.html")
.method(Method.GET)
.execute();
String sessionId = resCookie.cookie("PHPSESSID");
String fetypo = resCookie.cookie("fe_typo_user");
//these two above are the cookies
//the POST request, with the data asked
Connection.Response res = Jsoup.connect("http://www.bhtelecom.ba/imenik_telefon.html?a=search")
.data("di", some_data)
.data("br", some_data)
.data("btnSearch","Tra%C5%BEi")
.cookie("PHPSESSID", sessionId)
.cookie("fe_typo_user", fetypo)
.method(Method.POST)
.execute();
Document dok = …Run Code Online (Sandbox Code Playgroud) 我试图用Jsoup废弃网页.Jsoup似乎没有<input像Chrome那样捕获元素.
它缺少这些值:
<input type=?"hidden" id=?"fileId" value=?"3168935269">
<input type=?"hidden" id=?"secondsLeft" value=?"20">??
Run Code Online (Sandbox Code Playgroud)
使用Jsoup我提取了这些元素:
<input type="hidden" class="jsItemDirId" value="yRg1N-QP" />
<input type="hidden" class="jsItemFileId" value="i-EbooI0" />
<input type="hidden" id="fbAppId" value="255519317820035" />
<input type="hidden" id="sPrefix" value="http://search.4shared.com" />
<input type="hidden" class="sLink file" value="/q/CCAD/1" />
<input type="hidden" class="sLink video" value="/q/CCQD/1/video" />
<input type="hidden" class="sLink music" value="/q/CCQD/1/music" />
<input type="hidden" class="sLink photo" value="/q/CCQD/1/photo" />
<input type="hidden" class="sLink games" value="/q/CCQD/1/game" />
<input type="hidden" class="sLink book" value="/q/CCQD/1/books_office" />
<input type="hidden" class="sLink featured_videos" value="/q/CCQD/1/video" />
<input type="hidden" id="sBreadcrumbsPhrase" value="Searching" /> …Run Code Online (Sandbox Code Playgroud)