Skip to content

Commit

Permalink
Fix: HTML parser import error in Python2.7
Browse files Browse the repository at this point in the history
html.parser is for Python3, HTMLParser is used in Python2.2 and above
adding try-except allows to use the module into Python2.7
  • Loading branch information
dhondta committed Oct 29, 2015
1 parent 9f4cb19 commit 951b1c4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pws/google.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from bs4 import BeautifulSoup
from html.parser import HTMLParser
try:
from html.parser import HTMLParser
except ImportError:
from HTMLParser import HTMLParser
from time import sleep as wait
import re
import requests
Expand Down Expand Up @@ -206,4 +209,4 @@ def scrape_news_result(soup):
'time' : time,
}
results.append(temp)
return results
return results

0 comments on commit 951b1c4

Please sign in to comment.