Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mushfiq
Last active December 20, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mushfiq/6197787 to your computer and use it in GitHub Desktop.
Save mushfiq/6197787 to your computer and use it in GitHub Desktop.
An example of using super in python
import requests
from BeautifulSoup import BeautifulSoup
class crawlPyCentral(object):
def __init__(self, url='http://pythoncentral.org/'):
self.url = url
def getSoup(self):
response = requests.get(self.url)
soup = BeautifulSoup(response.content)
return soup
def getTitles(self):
soup = self.getSoup()
uls = soup.findAll('ul',{'class':'category-posts'})
for ul in uls:
lis = ul.findAll('a')
for li in lis:
yield li
class filteredCrawler(crawlPyCentral):
def getTitles(self, keyword):
for t in super(filteredCrawler, self).getTitles():
if t.text.find(keyword) > -1:
yield t.text
if __name__=='__main__':
f = filteredCrawler()
for title in f.getTitles('1'):
print title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment