parse_items
私はスパイダーにこのコードを持っています
def parse_items(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select("//li[@class='mod-result-entry ']")
items = []
for site in sites[:2]:
item = MyItem()
item['title'] = myfilter(site.select('dl/a').select("string()").extract())
item['company'] = myfilter(site.select('dl/h2/em').select("string()").extract())
items.append(item)
return items
今、Django モデルを使用してアイテムをデータベースに保存したいと考えています。私がこのように使用するだけでうまく機能している1つの方法
item = MYapp.MyDjangoItem()
item.title = myfilter(site.select('dl/a').select("string()").extract())
item.save()
今、これはうまくいっています
今、私はそれがデータベースに保存するための良い方法であることを知りたいです.
スクレイピーで記述されたアイテムパイプラインが必要な理由を意味します。これには何か利点がありますか。
Fir e,g これは私のパイプラインです
class MyPipeline(object):
def __init__(self):
self.ids_seen = set()
def process_item(self, item, spider):
Myitem = Myapp.DjamgoItem()
Myitem.title = item['title']
MyItem.save()
それでいいですか
また、私のコードはこのパイプラインをどのように呼び出しますか。私はこれと混同しています