这段抓取instapaper的python代码有什么问题,运行提示TypeError: 'NoneType' object is not iterable
defparse_index(self):totalfeeds=[]lfeeds=self.get_feeds()forfeedobjinlfeeds:feedtitle...
def parse_index(self):
totalfeeds = []
lfeeds = self.get_feeds()
for feedobj in lfeeds:
feedtitle, feedurl = feedobj
articles = []
#folder page
current_page = 1
#so we run the first time
articles_on_page = 1
#download articles while they are available and we don't have enough to satisfy max_articles_per_feed
while (articles_on_page>0 and len(articles)<self.max_articles_per_feed):
self.report_progress(0, _('Fetching feed')+' %s (%d)...'%((feedtitle if feedtitle else feedurl), current_page))
soup = self.index_to_soup(feedurl+u'/'+str(current_page))
#get and count number of items on current page
items = soup.findAll('a', attrs={'class':'actionButton textButton'})
articles_on_page = len(items)
# Go through each item, (each item is the 'Text' link) looking
# for the archive link, and secondary information (for
# description and date)
for item in items:
if item.has_key('href'):
article = {'url':item['href']}
if len(totalfeeds)==0:
return None
else:
return totalfeeds
中间省略了,关键是最后这几句,是不是返回值有问题? 展开
totalfeeds = []
lfeeds = self.get_feeds()
for feedobj in lfeeds:
feedtitle, feedurl = feedobj
articles = []
#folder page
current_page = 1
#so we run the first time
articles_on_page = 1
#download articles while they are available and we don't have enough to satisfy max_articles_per_feed
while (articles_on_page>0 and len(articles)<self.max_articles_per_feed):
self.report_progress(0, _('Fetching feed')+' %s (%d)...'%((feedtitle if feedtitle else feedurl), current_page))
soup = self.index_to_soup(feedurl+u'/'+str(current_page))
#get and count number of items on current page
items = soup.findAll('a', attrs={'class':'actionButton textButton'})
articles_on_page = len(items)
# Go through each item, (each item is the 'Text' link) looking
# for the archive link, and secondary information (for
# description and date)
for item in items:
if item.has_key('href'):
article = {'url':item['href']}
if len(totalfeeds)==0:
return None
else:
return totalfeeds
中间省略了,关键是最后这几句,是不是返回值有问题? 展开
1个回答
展开全部
您好,给你点拨一下,你的"-H"传递给process了么?:
PYTHON subprocess API里面有个communicate函数 可以传递输入(stdin)。
给你一个例子,希望你可以理解,test3传递了输入给test1,test1输出了接收到的参数。
test1:
import sys
input = sys.stdin.read()
sys.stdout.write('Received: %s'%input)
test3:
import subprocess
process = subprocess.Popen(['python', 'test1.py'], shell=False, stdin=subprocess.PIPE)
print process.communicate('How are you?')
领悟一下,获取process的输出你会的吧。
PYTHON subprocess API里面有个communicate函数 可以传递输入(stdin)。
给你一个例子,希望你可以理解,test3传递了输入给test1,test1输出了接收到的参数。
test1:
import sys
input = sys.stdin.read()
sys.stdout.write('Received: %s'%input)
test3:
import subprocess
process = subprocess.Popen(['python', 'test1.py'], shell=False, stdin=subprocess.PIPE)
print process.communicate('How are you?')
领悟一下,获取process的输出你会的吧。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询