本文整理汇总了Python中scraper.Scraper.fetch_items方法的典型用法代码示例。如果您正苦于以下问题:Python Scraper.fetch_items方法的具体用法?Python Scraper.fetch_items怎么用?Python Scraper.fetch_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scraper.Scraper
的用法示例。
在下文中一共展示了Scraper.fetch_items方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from scraper import Scraper [as 别名]
# 或者: from scraper.Scraper import fetch_items [as 别名]
def update(from_id, to_id, backsort):
"""
Update items between given ids
Use this command to fetch older data
"""
if from_id is None or not from_id.isdigit() or to_id is None or not to_id.isdigit() or backsort not in ('0', '1'):
print "Error. Expected parameters from_hn_id to_hn_id backsort (0 or 1)"
return
s = Scraper()
s.connect()
# Fetch and save items
save = lambda item_data: s.save_item(item_data)
item_ids = range(int(from_id), int(to_id))
if backsort == '1':
item_ids = reversed(item_ids)
s.fetch_items(item_ids, callback=save)
示例2: fix_ask_items
# 需要导入模块: from scraper import Scraper [as 别名]
# 或者: from scraper.Scraper import fetch_items [as 别名]
def fix_ask_items():
"""Temporary command to fix type:ask items appearing as links with no URL"""
s = Scraper()
s.connect()
items = (db.session.query(Item)
.with_entities(Item.id)
.filter(Item.subkind == 'ask')
# .filter(Item.raw_body == None)
.order_by(sqlalchemy.desc(Item.id))
.all()
)
# Fetch and save items
def save(item_data):
s.save_item(item_data)
print 'fixed '+str(item_data['id'])
item_ids = [item.id for item in items]
s.fetch_items(item_ids, callback=save)