如何在数据库中存储torrent链接?

时间:2012-06-28 09:47:58

标签: python django scrapy

我在包含磁力洪流列表的蜘蛛中有一个python列表。现在我如何将此列表/磁力洪流存储在数据库字段中? 这是代码:

class MySpider(BaseSpider):

    name = "myspider"
    allowed_domains = ["thepiratebay.se"]
    base_url = "http://www.thepiratebay.se/search/%s/"
    start_urls = []

    def __init__(self, *args, **kwargs):
        movies = Movie.objects.all()
        for movie in movies:
            self.start_urls.append(self.base_url % movie.name)
        super(MySpider, self).__init__(*args, **kwargs)

    def parse(self, response):
        self.log('Hi, this is an item page! %s' % response.url)
        hxs = HtmlXPathSelector(response)
        items = hxs.select('//table/tr/td[contains(@class, "detName")]')
        item = items
        item_name = hxs.select('//a[@class="detLink"]/text()').extract()[1]
        print item_name  #list containing movie names      
        torrent_link = hxs.select('//a[@title="Download this torrent using magnet"]/@href').extract()[1]
        print torrent_link # torrent_link contains list of torrent links

现在我想将这些链接保存在数据库中???怎么做???

2 个答案:

答案 0 :(得分:0)

假设您没有使用python进行数据库编程的经验,我建议您使用谷歌搜索“python数据库教程”(我建议从sqlite开始)并尝试按照它进行调整并使其适应您当前的脚本。

答案 1 :(得分:0)

如果您不知道如何保存到数据库,那么我高度建议您执行django tutorial here。它会向你展示sqlite的所有CRUD内容。