Scrapy只能爬取第一组数据
写的代码只能爬取网站第一组数据,后面的爬不了。@不二如是代码:
import scrapy
from tutorial.items import DmozItem
class DmozSpidera(scrapy.Spider):
name = 'dmoz'
allowed_domains = ['dmoz-odp.org']
start_urls = [
'https://www.dmoz-odp.org/Computers/Programming/Languages/Python/Books/',
'https://www.dmoz-odp.org/Computers/Programming/Languages/Python/Resources/'
]
def parse(self,response):
res = scrapy.selector.Selector(response)
i =1
sites = res.xpath('//*[@id="site-list-content"]')
items = []
for site in sites:
item = DmozItem()
ti = 'div[%d]/div/a/div' % i
li = 'div[%d]/div/a' % i
de = 'div[%d]/div/div' % i
item['title'] = site.xpath(ti).extract()
item['link'] = site.xpath(li).extract()
item['desc'] = site.xpath(de).extract()
items.append(item)
i += 1
return items
@不二如是 @不二如是
页:
[1]