Guest User

Untitled

a guest
Nov 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. def _extract_url_links(html):
  2. """extract url links
  3. >>> _extract_url_links('aa<a href="link1">link1</a>bb<a href="link2">link2</a>cc')
  4. ['link1', 'link2']
  5. """
  6. #"html.parser"はなるべくpython標準のparserモジュールを使うように指定しているBeautifulSoup()で
  7. #BeautifulSoupで扱えるようにしている。
  8. all_url = []
  9. body_soup = BeautifulSoup(html, "html.parser").find('body')
  10. #aタグを全て持ってくる。
  11. for child_tag in body_soup.findChildren():
  12. if child_tag.get('href') is not None:
  13. if '#' not in child_tag.get('href'):#or '.png' or '.jpg' or '.gif'
  14. if '.jpg' not in child_tag.get('href'):
  15. if '.png' not in child_tag.get('href'):
  16. if '.gif' not in child_tag.get('href'):
  17. all_url.append(child_tag.get('href'))
  18. return all_url
  19.  
  20. def _extract_url_links(html):
  21. """extract url links
  22. >>> _extract_url_links('aa<a href="link1">link1</a>bb<a href="link2">link2</a>cc')
  23. ['link1', 'link2']
  24. """
  25. #"html.parser"はなるべくpython標準のparserモジュールを使うように指定しているBeautifulSoup()で
  26. #BeautifulSoupで扱えるようにしている。
  27. all_url = []
  28. body_soup = BeautifulSoup(html, "html.parser").find('body')
  29. #aタグを全て持ってくる。
  30. for child_tag in body_soup.findChildren():
  31. if child_tag.get('href') is not None:
  32. if '#' not in child_tag.get('href') or '.jpg' not in child_tag.get('href') or '.png' not in child_tag.get('href') or'.gif' not in child_tag.get('href'):
  33. return all_url
  34.  
  35. import re
  36. m = re.search(r'ここの引数をどうしたらいいのかわかりません',child_tag.get('href'))
  37. if m is not None;
  38. all_url.append(child_tag.get('href'))
Add Comment
Please, Sign In to add comment