我在下面找到了答案.简而言之,ItemPipeline中的错误缩进导致它返回None.
我一直在尝试在Scrapy中编写一个CrawlSpider,之前从未使用过python.Spider爬行,调用回调函数,提取数据并填充项目,但它总是返回None.我用打印文章调用测试了它,一切都井然有序.我已经用屈服和回报尝试了这一点(虽然我仍然不明白其中的区别).坦率地说,我没有想法.下面是回调函数.//edit也添加了蜘蛛代码
class ZeitSpider(CrawlSpider):
name= xxxx
allowed_domains = ['example.com']
start_urls = ['http://www.example.com/%d/%d' %(JAHR,39)]
rules = (Rule(SgmlLinkExtractor(restrict_xpaths=('//ul[@class="teaserlist"]/li[@class="archiveteaser"]/h4[@class="title"]')),callback='parse_url',follow=True),)
def parse_url(self,response):
hxs = HtmlXPathSelector(response)
article = Article()
article['url']= response.url.encode('UTF-8',errors='strict')
article['author']= hxs.select('//div[@id="informatives"]/ul[@class="tools"]/li[@class="author first"]/text()').extract().pop().encode('UTF-8',errors='strict')
article['title']= hxs.select('//div[@class="articleheader"]/h1/span[@class="title"]/text()').extract().pop().encode('UTF-8',errors='strict')
article['text']= hxs.select('//div[@id="main"]/p/text()').extract().pop().encode('UTF-8',errors='strict')
article['excerpt'] = hxs.select('//p[@class="excerpt"]/text()').extract().pop().encode('UTF-8',errors='strict')
yield article
Run Code Online (Sandbox Code Playgroud)
和项目定义
class Article(Item):
url=Field()
author=Field()
text=Field()
title=Field()
excerpt=Field()
Run Code Online (Sandbox Code Playgroud) 我有下面的代码,如果我使用glfwGetKey()似乎工作,但因为它不会退出循环,甚至似乎没有调用输入函数.我尝试传递*输入而不是输入,但没有骰子.可能是什么导致了这个?
#include <display.h>
#include <GL/glfw.h>
#include <stdlib.h>
#include <stdio.h>
bool running;
void GLFWCALL input( int key, int action )
{
//if(key == GLFW_KEY_ESC ){
running = false;
//}
printf("%d",key);
}
int main(int argc, char* argv[])
{
running = true;
if(argc==3){
int width = atoi(argv[1]);
int height = atoi(argv[2]);
Display d(width,height);
glfwSetKeyCallback( *input );
d.open();
while(running){
glfwPollEvents();
printf("Running");
}
printf("\n %d,%d %d\n", width,height,GLFW_KEY_ESC);
d.close();
return 1;
}
else {
printf("Usage: GLFW_play width height");
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)