Get abstract of each page and hyperplinks within the whole page. :param text: wikipedia text, with hyperlinks
(text, abstract=None)
| 19 | |
| 20 | |
| 21 | def get_hyperlink(text, abstract=None): |
| 22 | """ |
| 23 | Get abstract of each page and hyperplinks within the whole page. |
| 24 | :param text: wikipedia text, with hyperlinks |
| 25 | """ |
| 26 | if abstract is None: |
| 27 | parts = text.split("\n\n", 1) |
| 28 | if len(parts) > 1: |
| 29 | abstract = parts[1].split('\n')[0] |
| 30 | else: |
| 31 | abstract = "" |
| 32 | |
| 33 | abs_hyperlink = re.findall(r'<a href="([^"]+)">', abstract) |
| 34 | full_hyperlink = re.findall(r'<a href="([^"]+)">', text) |
| 35 | abs_hyperlink = [_normalize(unquote(link)) for link in abs_hyperlink] |
| 36 | full_hyperlink = [_normalize(unquote(link)) for link in full_hyperlink] |
| 37 | return abs_hyperlink, full_hyperlink |
| 38 | |
| 39 | |
| 40 | def remove_hyperlink(text, abstract=False): |
no test coverage detected