我想从http://community.sellfree.co.kr/提取数据。Scrapy正在工作,但它似乎只爬取了
我希望蜘蛛程序可以爬行整个网站。
以下是我的代码:
页面上有两种链接。一种是
我该如何让爬虫跟随这两种链接?
start_urls
,没有爬取任何链接。我希望蜘蛛程序可以爬行整个网站。
以下是我的代码:
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from metacritic.items import MetacriticItem
class MetacriticSpider(BaseSpider):
name = "metacritic" # Name of the spider, to be used when crawling
allowed_domains = ["sellfree.co.kr"] # Where the spider is allowed to go
start_urls = [
"http://community.sellfree.co.kr/"
]
rules = (Rule (SgmlLinkExtractor(allow=('.*',))
,callback="parse", follow= True),
)
def parse(self, response):
hxs = HtmlXPathSelector(response) # The XPath selector
sites = hxs.select('/html/body')
items = []
for site in sites:
item = MetacriticItem()
item['title'] = site.select('//a[@title]').extract()
items.append(item)
return items
页面上有两种链接。一种是
onclick="location='../bbs/board.php?bo_table=maket_5_3'
,另一种是<a href="../bbs/board.php?bo_table=maket_5_1&sca=프로그램/솔루션"><span class="list2">solution</span></a>
。我该如何让爬虫跟随这两种链接?
CrawlSpider
пјље°ќиЇ•дЅїз”Ёclass MetacriticSpider(CrawlSpider):
гЂ‚ - paul trmbrthCrawlSpider
,并且不要覆盖parse
方法,请尝试使用其他用户建议的parse_item
方法。 - R. Max