我想从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>
如何让爬虫跟踪这两种链接?