所以我正在开发一个webapp,我需要从i class
获取style属性并从中提取背景URL以在app中使用它...
这是我的AsyncTask
方法:
public class GetImageBruh extends AsyncTask<Void, Void, Element> {
protected Element doInBackground(Void... voids) {
Element result = null;
ChatScreen.this.syncCookies();
int i = 0;
while (true) {
int tries = i + ChatScreen.REQUEST_STORAGE;
if (i >= ChatScreen.MAX_RETRY || result != null) {
return result;
}
Log.i("GetImageBruh", "doInBackground: Processing... Trial: " + tries);
Log.i("GetImageBruh", "Trying: " + ChatScreen.this.url);
Element notification = ChatScreen.this.getElement(ChatScreen.this.url);
if (notification != null) {
result = notification;
}
i = tries;
}
return result;
}
protected void onPostExecute(Element result) {
String imageUrl;
String style = result.select("div._4g34").select("i[aria-label=" + ChatScreen.this.friendName + "]").attr(AnalyticsEvents.PARAMETER_LIKE_VIEW_STYLE);
try {
imageUrl = style.substring(style.indexOf("https://"), style.indexOf(")")).replace("\"", BuildConfig.FLAVOR);
} catch (Exception e) {
imageUrl = null;
}
Log.d("GetImageBruh", "Style: " + imageUrl);
}
}
private Element getElement(String connectUrl) {
Element element = null;
try {
element = Jsoup.connect(connectUrl).header("Accept-Encoding", "gzip,deflate,sdch").userAgent(this.savedPreferences.getString("webview_user_agent", System.getProperty("http.agent"))).timeout(600000).cookie("m.facebook.com/messages/read/", CookieManager.getInstance().getCookie("m.facebook.com/messages/read")).get();
} catch (IllegalArgumentException e) {
Log.i(TAG, "Cookie sync problem occurred");
} catch (IOException ex) {
ex.printStackTrace();
}
return element;
}
此处friendName
等于John Smith
...
HTML结构类似于:
<div class="_4g34">
<div class="di">
<a class="profilePic">
<i class="img profpic" style="background.....">
</i>
</a>
</div>
</div>
什么是打印是“空”... 我在这段代码中做错了什么?