Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在数据库中存储torrent链接?_Python_Django_Scrapy - Fatal编程技术网

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

Python 如何在数据库中存储torrent链接?,python,django,scrapy,Python,Django,Scrapy,我有一个包含磁铁torrent列表的spider中的python列表。现在,我如何在数据库字段中存储此列表/磁铁种子? 代码如下: class MySpider(BaseSpider): name = "myspider" allowed_domains = ["thepiratebay.se"] base_url = "http://www.thepiratebay.se/search/%s/" start_urls = [] def __init_

我有一个包含磁铁torrent列表的spider中的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进行数据库编程的经验,我建议您在谷歌上搜索“python数据库教程”(我建议从sqlite开始),然后尝试按照该教程进行操作,并使其适应您当前的脚本。

如果您不知道如何保存到数据库,我强烈建议您这样做。它将向您展示sqlite的所有积垢

你尝试了什么不起作用?为了帮助我们,我们需要更多的信息。什么数据库引擎?桌子的结构是什么?什么python库?但主要是我们需要看看你已经尝试了什么?我在spider中获得了一个磁性torrent列表,还创建了一个模型,在其中保存链接,但我不知道如何在数据库字段中保存torrent链接。不要写评论编辑你的问题,这样我们就可以看到你做了什么,问题出在哪里了