本文整理汇总了Python中mailer.Mailer.send_email方法的典型用法代码示例。如果您正苦于以下问题:Python Mailer.send_email方法的具体用法?Python Mailer.send_email怎么用?Python Mailer.send_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailer.Mailer
的用法示例。
在下文中一共展示了Mailer.send_email方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Crawler
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_email [as 别名]
class Crawler():
def __init__(self, item, loc, category):
self.emailer = Mailer()
self.url = "http://www.gumtree.com/search?q={}&search_location={}&category={}".format(item, loc, category)
self.hist = self.read_history()
def find_new_items(self):
page = self.get_page()
links = self.scrape_page(page)
#links = [link for link in links if link not in self.hist]
self.emailer.send_email('[email protected]', links)
print self.emailer.advert_json
self.write_history(self.emailer.advert_json)
def get_page(self):
request = urllib2.Request(self.url)
request.add_header('User-Agent', '[email protected]')
return urllib2.urlopen(request).read()
def scrape_page(self, page):
source = BeautifulSoup(page)
body = source.body
pattern = re.compile("hlisting.*")
items = body.findAll("li", {"class": pattern})
item_links = []
for item in items:
item_links.append(item.findAll('a')[0]['href'])
return item_links
def read_history(self):
with open('history.txt', 'r') as f:
history = list((line.strip() for line in f))
return history
def write_history(self, links):
with open('history.txt', 'w') as f:
for link in links:
f.write(link + '\n')