Created
October 17, 2017 12:31
-
-
Save Cartman0/1413821f5185666bd7f89dbcfa72b947 to your computer and use it in GitHub Desktop.
はてなブログAPI サービス文書URIのレスポンスからコレクションURIを取得
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 | |
hatena_id = "<hatena id>" | |
blog_id = "<blog_id>" | |
password = "<api key>" | |
def get_collection_uri(hatena_id, blog_id, password): | |
service_doc_uri = "https://blog.hatena.ne.jp/{hatena_id:}/{blog_id:}/atom".format(hatena_id=hatena_id, blog_id=blog_id) | |
res_service_doc = requests.get(url=service_doc_uri, auth=(hatena_id, password)) | |
if res_service_doc.ok: | |
soup_servicedoc_xml = bs4.BeautifulSoup(res_service_doc.content, features="xml") | |
collection_uri = soup_servicedoc_xml.collection.get("href") | |
return collection_uri | |
return False | |
get_collection_uri(hatena_id, blog_id, password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment