从正在开发的多个网站获取数据。在第一个网站页面上,我卡住了我无法输出。 该应用应具有天然气和其他产品的当前价格,并且在其上单击时应显示该状态下的可用位置。
主要活动
. ~/.bash_profile
设置者和获取者
minikube ssh
cd /var/lib/boot2docker
sudo cp userdata.tar userdata-backup.tar
cd /home/docker
echo YOUR_SSH_PUBLIC_KEY_HERE >> .ssh/authorized_keys
sudo tar cf /var/lib/boot2docker/userdata.tar .
html解析活动
public class MainActivity extends AppCompatActivity implements
ParserResponseInterface{
private TextView headlineTextView;
private TextView articleTextView;
private TextView errorMessageTextView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
headlineTextView = (TextView) findViewById(R.id.headline);
articleTextView = (TextView) findViewById(R.id.article);
errorMessageTextView = (TextView) findViewById(R.id.errorMessage);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
Log.d("oncreate()","before htmlparser ");
//Execute AsyncTask for Parsing HTML
new
HtmlParser(this)
.execute("https://developer.android.com/training/index.html");
Log.d("oncreate()","eeeeeeeeeeexcute URl ");
}
@Override
public void onParsingDone(ArticleModel articleModel) {
progressBar.setVisibility(View.GONE);
if(articleModel!=null){
headlineTextView.setText(articleModel.getHeadline());
Log.i("onParsingDone: ", "headlineTextView : "
+headlineTextView);
articleTextView.setText(articleModel.getArticle());
Log.i("onParsingDone: ", "articleTextView : " +articleTextView);
}
else
errorMessageTextView.setText("Something wrong! Can't parse
HTML");
}
}
界面
public class ArticleModel {
private String headline;
private String article;
public ArticleModel(String headline, String article) {
this.headline = headline;
Log.i("ARTICLE MODEL","I AM IN SETTER BLOCK headline : "+ headline);
this.article = article;
Log.d("ARTICLE MODEL","I AM IN SETTER BLOCK article: "+article);
}
public String getHeadline() {
Log.i("ARTICLE MODEL","I AM IN SETTER BLOCK get headline headline :
"+ headline);
return headline;
}
public String getArticle() {
return article;
}
}
}
主要xml文件
public class HtmlParser extends AsyncTask<String, Void, ArticleModel> {
private ParserResponseInterface parserResponseInterface;
public HtmlParser(ParserResponseInterface parserResponseInterface){
this.parserResponseInterface = parserResponseInterface;
}
@Override
protected ArticleModel doInBackground(String... params) {
Log.d("DOINBACKGROUND","I AM IN DO IN BACKGROUND PARSE URL ");
String url = params[0];
ArticleModel articleModel = null;
String headline;
String article = "";
Document pageDocument;
Elements elements;
Elements articleElements;
try {
pageDocument = Jsoup.connect(url).get();
Log.i("HTMLPARSER","I AM IN TRY BLOCK TO GET URl ");
elements = pageDocument.select("#body-content");
Log.i("HTMLPARSER","I AM IN TRY BLOCK TO GET URl elements:
"+elements);
articleElements = pageDocument.select(".wrap .cols .col-1of2 p");
headline = elements.select("h1").text();
Log.i("HTMLPARSER","I AM IN TRY BLOCK TO GET URl headline::
"+headline);
for(Element element: articleElements){
article = article + element.text() + "\n\n";
Log.i("HTMLPARSER","I AM IN TRY BLOCK IN THAT FOR LOOP TO GET
URl article:: "+ article);
}
articleModel = new ArticleModel(headline, article);
Log.i("HTMLPARSER","I AM IN TRY BLOCK IN THAT FOR LOOP TO GET URl
article model:: "+ articleModel);
} catch (IOException e) {
e.printStackTrace();
}
return articleModel;
}