Created
October 18, 2017 08:18
-
-
Save Cartman0/949300147ddcf6c98999162fccd2075d to your computer and use it in GitHub Desktop.
はてなブログAPI entry_idから記事のコンテンツ要素(文字列)を取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import bs4 | |
def get_entry_content_str(hatena_id, blog_id, password, entry_id): | |
member_uri = "https://blog.hatena.ne.jp/{hatena_id}/{blog_id}/atom/entry/{entry_id}".format(hatena_id=hatena_id, blog_id=blog_id,entry_id=entry_id) | |
res_member = requests.get(member_uri, auth=(hatena_id, password)) | |
if not res_member.ok: | |
print("Failed: status_code: " + str(res_member.status_code)) | |
return False | |
soup_response_xml = bs4.BeautifulSoup(res_member.content, features="xml") | |
return soup_response_xml.find("content").string | |
get_entry_content_str(hatena_id, blog_id, password, entry_id='8599973812308945752') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment