Compare commits
2 commits
340feaa7ed
...
3858d2a556
Author | SHA1 | Date | |
---|---|---|---|
Tristan Daniël Maat | 3858d2a556 | ||
Tristan Daniël Maat | e61a31154f |
|
@ -38,7 +38,7 @@ def main():
|
||||||
print(f"Downloading {link[0]} ({i}/{len(links)})")
|
print(f"Downloading {link[0]} ({i}/{len(links)})")
|
||||||
|
|
||||||
text = download_article_text(link[0])
|
text = download_article_text(link[0])
|
||||||
with open(f"articles-qinghai/{link[1]}_{i}.txt") as f:
|
with open(f"articles-qinghai/{link[1]}_{i}.txt", "w+") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ def get_article_links(page: int) -> List[Tuple[str, str]]:
|
||||||
|
|
||||||
def download_article_text(link: str) -> str:
|
def download_article_text(link: str) -> str:
|
||||||
"""Get the text of an article from its link."""
|
"""Get the text of an article from its link."""
|
||||||
soup = BeautifulSoup(requests.get(link).text, "html.parser")
|
request = requests.get(link)
|
||||||
|
request.encoding = "gbk" # The website responds with the wrong encoding
|
||||||
|
soup = BeautifulSoup(request.text, "html.parser")
|
||||||
return soup.find(class_="page_text").get_text().strip()
|
return soup.find(class_="page_text").get_text().strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue