这是我的调试堆栈:
Thread [<1> main] (Suspended (exception IllegalArgumentException))
<VM does not provide monitor information>
HttpConnection.connect(String) line: 30
Jsoup.connect(String) line: 73
Parsing.doInBackground(String...) line: 23
MainActivity$1.onClick(View) line: 29
Button(View).performClick() line: 4424
View$PerformClick.run() line: 18383
Handler.handleCallback(Message) line: 733
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 95
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4998
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 515
ZygoteInit$MethodAndArgsCaller.run() line: 777
ZygoteInit.main(String[]) line: 593
荷兰国际集团
这是我的代码:
package com.example.pricetracker;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import android.os.AsyncTask;
public class Parsing extends AsyncTask<String,Void,String> {
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
Document htmlFile = null;
Element price = null;
try {
htmlFile = Jsoup.connect("www.amazon.in/Google-Nexus-D821-16GB-Black/dp/B00GC1J55C/ref=sr_1_1?s=electronics&ie=UTF8&qid=1421161258&sr=1-1&keywords=Google").get();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
catch (Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
try{
if( htmlFile.getElementById("priceblock_ourprice")!= null)
{
price = htmlFile.getElementById("priceblock_ourprice");
}
else
{
price = htmlFile.getElementById("priceblock_saleprice");
}
}catch(Exception e)
{
e.printStackTrace();
}
return (String)price.toString();
}
如何从网址获取数据?
这个问题的原因是什么?如何解决这个问题?
我被困在这里超过一天。
任何想法的人?提前谢谢。
答案 0 :(得分:1)
尝试使用指定方案的URL(http或https):
htmlFile = Jsoup.connect("http://www.amazon.in/Google-Nexus-D821-16GB-Black/dp/B00GC1J55C/ref=sr_1_1?s=electronics&ie=UTF8&qid=1421161258&sr=1-1&keywords=Google").get();
^^^^^^^^
修改强>
来自JavaDoc for JSoup.connect(String):
> url - URL to connect to. The protocol must be http or https.