commit baf18f9fc50a0b6fef50460a76c33b2ddc57486e
parent 19720ba8807a38c0466c10871a1227f283e87b3b
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sun, 11 Oct 2015 02:47:28 +0200
work around bs4 misbehavior in old versions
Diffstat:
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/get_propositions.py b/get_propositions.py
@@ -25,7 +25,17 @@ if __name__ == '__main__':
time.sleep(1)
tree = BeautifulSoup(data.text, 'html.parser')
- for div in tree.find_all('div', class_='opinion__data'):
+ # the following does not work on older bs4 versions
+ #for div in tree.find_all('div', class_='opinion__data'):
+ for div in tree.find_all('div'):
+ try:
+ c = div.get("class")
+ except KeyError:
+ continue
+ if isinstance(c, list):
+ c = c[0]
+ if c != 'opinion__data':
+ continue
res_url = None
for a in div.find_all('a'):
v = a.get('href')
diff --git a/get_votes.py b/get_votes.py
@@ -29,7 +29,16 @@ if __name__ == '__main__':
time.sleep(1)
votes_tree = BeautifulSoup(data.text, 'html.parser')
- for div in votes_tree.find_all('div', class_='opinion__data'):
+ # see get_propositions.py
+ for div in tree.find_all('div'):
+ try:
+ c = div.get("class")
+ except KeyError:
+ continue
+ if isinstance(c, list):
+ c = c[0]
+ if c != 'opinion__data':
+ continue
res_url = None
for a in div.find_all('a'):
v = a.get('href')