articles=response.css("#content > article:nth-child(5) p")
sgg="";
for item in articles:
sgg = sgg+item.extract()
data=urllib.urlencode({ 'title':title ,"describle":describle,"article":sgg} );
我想把sgg+item.extract() 转换为字符串.转换为urlcode.发送出去.
不过我碰到问题是这个
articles=response.css("#content > article:nth-child(5) p")
for item in articles: print ( type(item.extract()) )
输出
<type 'unicode'>
所以如果
data = {
'title': title,
'describle': describle,
'article': article
}
print urllib.urlencode(data);
就报错了
高洛峰2017-04-17 17:58:29
I don’t know what you mean by efficient, please post a more readable code
articles = response.css("#content > article:nth-child(5) p")
article = ''.join([_.extract() for _ in articles])
data = {
'title': title,
'describle': describle,
'article': article
}
print urllib.urlencode(data);
Please compare this code again
import urllib
data = {
'title': '标题',
'describle': 'abc',
'article': u'中文'.encode('utf-8')
}
print urllib.urlencode(data);