【问题标题】:How to store torrent links in a database?如何将种子链接存储在数据库中?
【发布时间】:2012-06-29 19:37:49
【问题描述】:

我在一个包含磁铁种子列表的蜘蛛中有一个 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

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

【问题讨论】:

  • 你尝试了什么不起作用?
  • 为了帮助我们需要更多信息。什么数据库引擎?什么是表结构?什么python库?但主要是我们需要看看你已经尝试过什么?
  • 我在蜘蛛中获得了一个磁力种子列表,还创建了一个模型来保存链接,但我不知道如何在数据库字段中保存种子链接..
  • 不要写 cmets 编辑你的问题,这样我们就可以看到你做了什么,有什么问题

标签: python django scrapy


【解决方案1】:

假设您没有使用 python 进行数据库编程的经验,我建议您在 Google 上搜索“python 数据库教程”(我建议从 sqlite 开始),然后尝试按照您当前的脚本进行调整。

【讨论】:

    【解决方案2】:

    如果您不知道如何保存到数据库,那么我强烈建议您使用django tutorial here。它将向您展示所有使用 sqlite 的 CRUD 内容。

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 1970-01-01
      • 2018-11-07
      • 2011-12-15
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2012-01-14
      • 2015-02-18
      相关资源
      最近更新 更多