基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.3 KiB

  1. import 'package:dio/dio.dart';
  2. import 'package:zhiying_comm/zhiying_comm.dart';
  3. // 淘宝详情图抓取
  4. class TaobaoLoader {
  5. static Future<List<String>> loadImages(String id) async {
  6. String url =
  7. 'http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?api=mtop.taobao.detail.getdesc&appkey=12574478&data={"type":"0","f":"TB1AsvbfnqWBKNjSZFx8qwpLpla","id":"${id.toString()}"}&dataType=json&jsv=2.4.11&sign=e93a97b7e9a9a459297f4e689051c895&t=1538180732308&type=json';
  8. Dio dio = Dio();
  9. Response response = await dio.get(url);
  10. // Logger.debug(response.data.toString());
  11. Map<String, dynamic> json = Map<String, dynamic>.from(response.data);
  12. List<String> images = List();
  13. try {
  14. Map<String, dynamic> data = json['data'];
  15. List list = json['data']['wdescContent']['pages'];
  16. for (var item in list) {
  17. Logger.debug(item);
  18. RegExp exp = new RegExp("(?<=<img(.*?)>)(.*?)(?=</img>)");
  19. String image = exp.stringMatch(item.toString());
  20. if (image != null && image != '') {
  21. if (image.startsWith('//')) {
  22. images.add('http:' + image);
  23. } else
  24. if (image.startsWith('https://') || image.startsWith('http://')) {
  25. images.add(image);
  26. }
  27. }
  28. }
  29. } catch (err) {
  30. Logger.error(err);
  31. }
  32. return images;
  33. }
  34. }