-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved extract_cite_refs to parse_utils
- Loading branch information
1 parent
23f3310
commit 10ac81b
Showing
5 changed files
with
54 additions
and
97 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# parse_utils.py | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def extract_cite_refs(html): | ||
|
||
soup = BeautifulSoup(html, "html.parser") | ||
# for link in soup.find_all("a"): | ||
# print(link.get("href")) | ||
|
||
ref_wrapper = soup.find("div", class_="mw-references-wrap") | ||
|
||
refs = [] | ||
|
||
if ref_wrapper: | ||
|
||
references_list = ref_wrapper.find("ol", class_="references") | ||
|
||
ref_counter = 0 | ||
for ref in references_list.find_all("li"): | ||
ref_counter += 1 | ||
page_refs = [] | ||
for link in ref.find_all("a"): | ||
# span.mw-linkback-text children should have a citeref link | ||
if link.find("span", class_="mw-linkback-text"): | ||
page_refs.append( | ||
{ | ||
"href": link.get("href"), | ||
"id": link.get("id"), | ||
} | ||
) | ||
|
||
span_link = ref.find("span", class_="mw-reference-text") | ||
raw_data = None | ||
if span_link: | ||
link_data = span_link.find("link") | ||
if link_data: | ||
raw_data = link_data.get("data-mw") | ||
|
||
refs.append( | ||
{ | ||
"id": ref.get("id"), | ||
# "ref_index": ref_counter, | ||
"raw_data": raw_data, | ||
"page_refs": page_refs, | ||
} | ||
) | ||
|
||
return refs |
Submodule WikidataIntegrator
deleted from
5db457
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters