我正试图让我的蜘蛛工作。这是我在蜘蛛中的代码:
start_urls = ["http://www.khmer24.com/"]
rules = (
Rule(SgmlLinkExtractor(allow=(r'ad/\w+/67-\d+\.html',),
),
callback='parse_items'),
)
示例网址如下所示:
http
://www.khmer24.com/ad/honda-click-2012-98/67-258149.html
我想保留“ad”和“67-”
的输出scrapy crawl khmer24
是:
Crawled (200) <GET http://www.khmer24.com/> (referer: None)
我不知道为什么这是我的整个代码:
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
class MySpider(CrawlSpider):
name = "khmer24"
allowed_domains = ["khmer24.com"]
start_urls = ["http://www.khmer24.com/"]
rules = (
Rule(SgmlLinkExtractor(allow=(r'ad/\w+/67-\d+\.html',),
),
callback='parse_items'),
)
def parse_items(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.select("//div[@class='innerbox']/h1/text()")
return(titles)