试着刮掉一个Y!组和我可以从一个页面获取数据,但仅此而已。我有一些基本的规则,但它们显然是不正确的。有人已经解决这个问题了吗?
class YgroupSpider(CrawlSpider):
name = "yahoo.com"
allowed_domains = ["launch.groups.yahoo.com"]
start_urls = [
"http://launch.groups.yahoo.com/group/random_public_ygroup/post"
]
rules = (
Rule(SgmlLinkExtractor(allow=('message','messages' ), deny=('mygroups', ))),
Rule(SgmlLinkExtractor(), callback='parse_item'),
)
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('/html')
item = Item()
for site in sites:
item = YgroupItem()
item['title'] = site.select('//title').extract()
item['pubDate'] = site.select('//abbr[@class="updated"]/text()').extract()
item['desc'] = site.select("//div[contains(concat(' ',normalize-space(@class),' '),' entry-content ')]/text()").extract()
return item发布于 2011-03-27 09:57:34
看起来你几乎不知道自己在做什么。我是Scrapy的新手,但我想你会想要像Rule(SgmlLinkExtractor(allow=('http\://example\.com/message/.*\.aspx', )), callback='parse_item'),这样的东西,试着写一个正则表达式,匹配你想要的完整链接URL。而且,看起来你只需要一条规则。将回调添加到第一个回调中。链接提取器匹配与allow中的正则表达式匹配的每个链接,并从那些链接中排除那些由deny匹配的链接,然后从那里加载剩余的每个页面并将其传递到parse_item。
我说这一切的时候,并不真正了解你正在进行数据挖掘的页面以及你想要的数据的性质。您需要在页面中使用这种爬行器,该页面包含指向包含所需数据的页面的链接。
https://stackoverflow.com/questions/5406832
复制相似问题