내가 멍청한 녀석이라고 말하면서 시작하자.작은 따옴표와 큰 따옴표로 dict을 구문 분석 할 때 SyntaxError가 발생합니까?
그래서 저는 pytumblr API를 사용하여 Tumblr에서 블로그 게시물을 가져옵니다. 게시물을 검색하고 게시물 내용 만 추출하고 싶습니다. 기술적으로 Tumblr이 dict
으로 나에게 전송하지만 형식이 매우 혼란 스럽습니다. 그 외에도, 그것은 작은 따옴표와 큰 따옴표를 모두 사용합니다!
post = client.posts(blogName, type = 'text', tag = 'suggestion', limit = 1)
postformat = str(post[u'posts']).replace("[", "").replace("]", "")
blog = dict(ast.literal_eval(postformat))
print(post[u'body']).replace("<p>", "").replace("</p>", "")
첫째, 텀블러는 3 키를 나에게 매우 큰 사전을 제공하지만, 그들 각각은 그 안에 사전을 가지고 : 여기 내 코드는! (???). 그래서, 내가 찾고있는 첫 번째 키를 가져 와서 그 키의 내용을 다시 ast를 사용하는 dict로 변환해야합니다. 그것을 시도 할 때, 나는 다른 오류가났다. 따라서 post
번 괄호를 삭제하고 ast를 사용하여 콘텐츠를 시도하고 해석했습니다. 그러나 내가 할 때, t는 3 행에 SyntaxError를 던집니다. 여기에 post[u'posts']
이라는 원시적이고 매우 혼란스러운 형식이 있습니다. 유래 한 줄에두고 있기 때문에, 나는 또한 구문 오류가 브래킷의 당신의 제거로 인해 발생 http://pastebin.com/9fnuS2F6
{u'body': u'<p>Concept: we’re in a cute little cottage, surrounded by flowers. I’m making breakfast and you’re on your way home from walking the dogs. We keep our own bees and collect honey from them; they are as happy and safe as we are.</p>', u'liked': False, u'followed': False, u'reblog_key': u'tlPNsk6e', u'reblog': {u'comment': u'<p>Concept: we\u2019re in a cute little cottage, surrounded by flowers. I\u2019m making breakfast and you\u2019re on your way home from walking the dogs. We keep our own bees and collect honey from them; they are as happy and safe as we are.</p>', u'tree_html': u''}, u'can_send_in_message': True, u'id': 146647556007L, u'post_url': u'http://affectionsuggestion.tumblr.com/post/146647556007/concept-were-in-a-cute-little-cottage', u'can_reply': True, u'title': None, u'tags': u'queued', u'suggestion', u'suggestion blog', u'concept', u'bees', u'love', u'future', u'happy', u'happiness', u'couple', u'relationship', u'nature', u'lesbians', u'cute', u'highlighted': , u'recommended_source': None, u'state': u'published', u'short_url': u'https://tmblr.co/ZzO-5i28au1_d', u'type': u'text', u'recommended_color': None, u'format': u'html', u'timestamp': 1467190899, u'note_count': 523, u'trail': {u'content': u'<p>Concept: we\u2019re in a cute little cottage, surrounded by flowers. I\u2019m making breakfast and you\u2019re on your way home from walking the dogs. We keep our own bees and collect honey from them; they are as happy and safe as we are.</p>', u'content_raw': u'<p>Concept: we\u2019re in a cute little cottage, surrounded by flowers. I\u2019m making breakfast and you\u2019re on your way home from walking the dogs. We keep our own bees and collect honey from them; they are as happy and safe as we are.</p>', u'is_current_item': True, u'blog': {u'active': True, u'theme': {u'title_font_weight': u'bold', u'title_color': u'#444444', u'header_bounds': u'', u'title_font': u'Gibson', u'link_color': u'#3D7291', u'header_image_focused': u'https://secure.assets.tumblr.com/images/default_header/optica_pattern_05.png?_v=671444c5f47705cce40d8aefd23df3b1', u'show_description': True, u'show_header_image': False, u'header_stretch': True, u'body_font': u'Helvetica Neue', u'show_title': True, u'header_image_scaled': u'https://secure.assets.tumblr.com/images/default_header/optica_pattern_05.png?_v=671444c5f47705cce40d8aefd23df3b1', u'avatar_shape': u'square', u'show_avatar': False, u'background_color': u'#FEB0B0', u'header_image': u'https://secure.assets.tumblr.com/images/default_header/optica_pattern_05.png?_v=671444c5f47705cce40d8aefd23df3b1'}, u'share_following': False, u'name': u'affectionsuggestion', u'share_likes': False}, u'is_root_item': True, u'post': {u'id': u'146647556007'}}, u'date': u'2016-06-29 09:01:39 GMT', u'slug': u'concept-were-in-a-cute-little-cottage', u'blog_name': u'affectionsuggestion', u'summary': u"Concept: we're in a cute little cottage, surrounded by flowers. I'm making breakfast and you're on your way home from walking..."}
btw, 나는이 게시물에서 'u'body']'를 얻고 싶습니다. 사전에있는 첫 번째 키 –
정보가 여러 번 반복되는 이유는 무엇입니까? 게시물은 10 개 장소에 나타납니다. –
'post'의 내용은 정확히 무엇입니까? 두 번째 라인이 왜 있는지 이해할 수 없습니다. – RemcoGerlich