我正在尝试从网站获取奖品信息。首先我必须填写一个表格,然后我想按下提交按钮,这样我就得到了新页面,然后我想从新页面中的一个 id 中获取一个链接,但我不知道该怎么做。
这是我的代码:
package com.sigustgebran.appsl;
import android.os.Bundle;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainAct extends Activity {
TextView display;
String anerror = "error";
// url
static final String SL_URL = "http://reseplanerare.sl.se/bin/query.exe/sn?OK#focus";
@Override
protected void onCreate(Bundle savedInstanceState) {
// set layout view
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
display = (TextView) findViewById(R.id.tvDisplay);
// process
try {
display.setText(gethref());
} catch (Exception ex) {
display.setText(anerror);
}
}
protected String gethref() throws Exception {
Document doc = Jsoup.connect(SL_URL)
.userAgent("Mozilla/5.0")
.data("existCustomerProfileFlag", "yes")
.data("REQcustomerProfileFlag", "1")
.data("queryPageDisplayed", "yes")
.data("ignoreTypeCheck", "yes")
.data("HWAI=JS!ajax", "yes")
.data("HWAI=JS!js", "yes")
.data("SetGlobalOptionGO_displayDataInTable", "yes")
.data("advancedSettingsChanged", "yes")
.data("REQ0JourneyStopsS0A", "255")
.data("ignoreTypeCheck", "yes")
.data("REQ0JourneyStopsS0G", "rosenmalm")
.data("REQ0JourneyStopsS0ID", "A=1@O=Carin Bååts gata (Södertälje)@X=17683166@Y=59194956@U=74@L=300107648@B=1@p=1369809363@")
.data("REQ0JourneyStopsZ0A", "255")
.data("REQ0JourneyStopsZ0G", "nacka trafikplats")
.data("REQ0JourneyStopsZ0ID", "A=1@O=ABB@X=17952752@Y=59336868@U=74@L=300109110@B=1@p=1369809363@")
.data("REQ0HafasUnsharpSearch", "1")
.data("existUnsharpSearch", "yes")
.data("REQ0HafasChangeTime", "0")
.data("REQ0HafasSearchForw", "1")
.data("REQ0HafasSearchForw", "0")
.data("REQ0JourneyDate", "+1")
.data("REQ0JourneyTime", "21:20")
.data("start", "Sök resa")
.data("REQ0JourneyStops1A", "1")
.data("REQ0JourneyStops1G", "")
.data("REQ0JourneyStopover1", "")
.data("REQ0JourneyProduct_prod_1", "1")
.data("REQ0JourneyProduct_prod_0", "1")
.data("REQ0JourneyProduct_prod_2", "1")
.data("REQ0JourneyProduct_prod_3", "1")
.data("REQ0JourneyProduct_prod_6", "1")
.data("REQ0JourneyProduct_prod_7", "1")
.data("REQ0JourneyProduct_prod_5", "1")
.data("lineFilterRestrict", "2") //????
.data("lineFilterExclude", "1")//?????
.data("REQ0HafasOpFilter_value", "")
.data("REQ0JourneyDep_Foot_maxDist", "2000")
.data("REQ0HafasNoOfChanges", "1000:1")
.data("REQ0HafasChangeMode", "1")
.data("REQ0HafasChangeTime", "0")
.data("REQ0HafasChangeMode", "2")
.data("REQ0HafasChangeSupplement", "0:0")
.data("REQ0HafasChangeMode", "4")
.data("REQ0HafasChangePercent", "70")
.data("start=1&SetGlobalOptionGO_displayAdvSearch=no&OK", "Sök resa")
.post();
Elements test = doc.select("div#hideLinkFaresC1-0 "); // <--- I want the href link from this id
return test.text();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}