Replace urllib with self.index_to_soup()

urllib is no longer used to make requests. Instead self.index_to_soup() is called, with raw=True.
This commit is contained in:
shinozukayohei 2020-12-21 12:18:27 -08:00 committed by GitHub
parent 526969213c
commit 7567ced528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,6 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
import urllib.request
try:
from http.cookiejar import Cookie
except ImportError:
@ -267,8 +265,8 @@ class Economist(BasicNewsRecipe):
self.log('Got cover:', self.cover_url)
else:
date8 = self.INDEX[-10:].replace('-', '')
resource = urllib.request.urlopen("https://www.economist.com/weeklyedition/archive?year={}".format(date8[:4]))
archive = resource.read().decode(resource.headers.get_content_charset())
archive_url = "https://www.economist.com/weeklyedition/archive?year={}".format(date8[:4])
archive = self.index_to_soup(archive_url, raw=True).decode("utf-8")
if date8 in archive:
parts = archive.split(date8)
self.cover_url = parts[-3].split(',')[-1]+date8+parts[-2].split()[0]