从 android 中的 news.bitcoin.com 获取 RSS 提要时未找到文件异常
file not found exception while fetching RSS feed from news.bitcoin.com in android
将 link 添加到 RSS 提要:https://news.bitcoin.com/feed/
到目前为止,这是我的代码:
主要活动:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RSSDataDownload downloadTask = new RSSDataDownload();
downloadTask.execute();
}
public static class RSSDataDownload extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
//DOESN'T WORK, FILE NOT FOUND EXCEPTION:
String MY_URL="https://news.bitcoin.com/feed" ;
try {
URL url = new URL(MY_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream inputStream = connection.getInputStream();
processXML(inputStream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void processXML(InputStream inputStream) throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document XMLdocument= builder.parse(inputStream);
Element rootElement=XMLdocument.getDocumentElement(); //root element of the XML Document
Log.d("XML",rootElement.getTagName());
}
}
}
以上代码适用于:http://www.bitnewz.net/rss/Feed 和 http://bitcoin.worldnewsoffice.com/rss/category/1/ 和其他几个 RSS 提要,但不适用于 https://news.bitcoin.com/feed/。
有什么特殊原因吗?如何绕过它?
我不知道你面临的问题是什么,但是 https://news.bitcoin.com/feed/ 通过使用这个库为我工作。
你可以从 RSS-Parser 库中得到这个想法:
https://github.com/prof18/RSS-Parser
将 link 添加到 RSS 提要:https://news.bitcoin.com/feed/
到目前为止,这是我的代码:
主要活动:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RSSDataDownload downloadTask = new RSSDataDownload();
downloadTask.execute();
}
public static class RSSDataDownload extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
//DOESN'T WORK, FILE NOT FOUND EXCEPTION:
String MY_URL="https://news.bitcoin.com/feed" ;
try {
URL url = new URL(MY_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream inputStream = connection.getInputStream();
processXML(inputStream);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void processXML(InputStream inputStream) throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document XMLdocument= builder.parse(inputStream);
Element rootElement=XMLdocument.getDocumentElement(); //root element of the XML Document
Log.d("XML",rootElement.getTagName());
}
}
}
以上代码适用于:http://www.bitnewz.net/rss/Feed 和 http://bitcoin.worldnewsoffice.com/rss/category/1/ 和其他几个 RSS 提要,但不适用于 https://news.bitcoin.com/feed/。
有什么特殊原因吗?如何绕过它?
我不知道你面临的问题是什么,但是 https://news.bitcoin.com/feed/ 通过使用这个库为我工作。
你可以从 RSS-Parser 库中得到这个想法: https://github.com/prof18/RSS-Parser