Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wyouflf committed Sep 28, 2019
1 parent 44b9b08 commit 24222c5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions sample/src/main/java/org/xutils/sample/ImageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
public class ImageFragment extends BaseFragment {

private String[] imgSites = {
"http://www.nipic.com/newpic/1.html",
"http://www.nipic.com/topic/show_27202_1.html"
"http://m.haopic.me/touxiang",
"http://m.haopic.me/touxiang/page/2",
"http://m.haopic.me"
};

ImageOptions imageOptions;
Expand Down Expand Up @@ -75,6 +76,10 @@ private void onImageItemClick(AdapterView<?> parent, View view, int position, lo
}

private void loadImgList(String url) {
RequestParams params = new RequestParams(url);
params.setUseCookie(true);
// 随意找的图片, 模拟浏览器UA, 防止被屏蔽
params.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.94");
x.http().get(new RequestParams(url), new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
Expand Down Expand Up @@ -223,6 +228,18 @@ public static List<String> getImgSrcList(String htmlStr) {
//pics.add("http://f.hiphotos.baidu.com/zhidao/pic/item/2fdda3cc7cd98d104cc21595203fb80e7bec907b.jpg");
}
}

regEx_img = "<img.*?src=\"//(.*?).jpg\""; // 图片链接地址
p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
m_image = p_image.matcher(htmlStr);
while (m_image.find()) {
String src = m_image.group(1);
if (src.length() < 100) {
pics.add("http://" + src + ".jpg");
//pics.add("http://f.hiphotos.baidu.com/zhidao/pic/item/2fdda3cc7cd98d104cc21595203fb80e7bec907b.jpg");
}
}

return pics;
}

Expand Down

0 comments on commit 24222c5

Please sign in to comment.