[英]how to get parse this span id element with jsoup in android studio?
I want to parse the span id = shd2b from this url in my android studio project, https://www.exchangerates.org.uk/Euros-to-Rupees-currency-conversion-page.html
我使用下面的 java 代碼對其進行解析並顯示在 textview 框中。
@Override protected Void doInBackground(Void... voids) { //Connect to the website String url = "https://www.exchangerates.org.uk/Euros-to-Rupees-currency-conversion-page.html"; //Get the title of the website Document doc = null; doc = (Document) Jsoup.parse(url); eurotoinr = doc.getElementById("span.shd2b"); return null; } @Override protected void onPostExecute(Void aVoid) { progressDialog.dismiss(); textView.setText((CharSequence) eurotoinr); }
當我運行它時,模擬器設備中沒有顯示任何內容。 有人可以幫我解決這個問題嗎?
如果我的描述不清楚或無法理解,請原諒我。 我只是在這次鎖定期間開始學習 android 工作室,並且是堆棧溢出的新手。
我看到兩個錯誤。
<html>
<head></head>
<body>
https://www.exchangerates.org.uk/Euros-to-Rupees-currency-conversion-page.html
</body>
</html>
因為您使用了錯誤的方法,並且您的字符串被解析為 HTML 片段。 它不會嘗試下載任何東西。
你應該使用
doc = Jsoup.connect(url).get();
然后它下載 HTML 並正確解析。
doc.getElementById("span.shd2b");
將返回 null 因為span.shd2b
不是有效的 id。 id是shd2b;
使用doc.getElementById("shd2b;");
它選擇預期的元素:<span id="shd2b;">82.9337</span>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.