Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. /**
  2. * jsoup 工具包
  3. * founder
  4. * @author XueLiang
  5. * @date 2016年9月23日 下午3:16:36
  6. * @version 1.0
  7. */
  8. public class JsoupUtils {
  9.  
  10. /**
  11. * 支持 meta 标签跳转
  12. * @param document
  13. * @return
  14. * @throws IOException
  15. * @throws URISyntaxException
  16. */
  17. public Document supportMetaRefresh(Document document) throws IOException, URISyntaxException {
  18. String refresh = getMetaValue(document, "refresh");
  19. if (refresh == null) {
  20. return document;
  21. }
  22. String baseUri = document.baseUri();
  23. URI uri = new URI(baseUri);
  24. Matcher m = Pattern.compile("(?si)\\d+;\\s+url=(.+)|\\d+").matcher(refresh);
  25. // find the first one that is valid
  26. if (m.matches()) {
  27. String refreshUrl = m.group(1);
  28. if (refreshUrl != null) {
  29. Document doc = Jsoup.connect(uri.resolve(refreshUrl).toString()).userAgent("Mozilla")
  30. .followRedirects(true).get();
  31. return supportMetaRefresh(doc);
  32. }
  33. }
  34. return document;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement