这是我的工作代码:
from scrapy.item import Item, Field
class Test2Item(Item):
title = Field()
from scrapy.http import Request
from scrapy.conf import settings
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
class Khmer24Spider(CrawlSpider):
name = 'khmer24'
allowed_domains = ['www.khmer24.com']
start_urls = ['http://www.khmer24.com/']
USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22 AlexaToolbar/alxg-3.1"
DOWNLOAD_DELAY = 2
rules = (
Rule(SgmlLinkExtractor(allow=r'ad/.+/67-\d+\.html'), callback='parse_item', follow=True),
)
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
i = Test2Item()
i['title'] = (hxs.select(('//div[@class="innerbox"]/h1/text()')).extract()[0]).strip(' \t\n\r')
return i
它只能废弃 10 或 15 条记录。总是随机数!我无法获取所有具有类似http://www.khmer24.com/ad/any-words/67-anynumber.html模式的页面
我真的怀疑 Scrapy 由于重复请求而完成了爬网。他们建议使用dont_filter = True
但是,我不知道将它放在我的代码中的哪个位置。
我是 Scrapy 的新手,真的需要帮助。