【发布时间】: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 编辑你的问题,这样我们就可以看到你做了什么,有什么问题