{"id":11,"date":"2018-05-05T01:24:00","date_gmt":"2018-05-04T16:24:00","guid":{"rendered":"https:\/\/www.oshaw53.com\/blog\/?p=11"},"modified":"2022-07-02T01:27:24","modified_gmt":"2022-07-01T16:27:24","slug":"evernote-webclip-automation-with-selenium","status":"publish","type":"post","link":"https:\/\/www.oshaw53.com\/blog\/2018\/05\/05\/evernote-webclip-automation-with-selenium\/","title":{"rendered":"Selenium\u306b\u3088\u308bEvernote\u306e\u81ea\u52d5\u30af\u30ea\u30c3\u30d7"},"content":{"rendered":"\n<p>\u30a4\u30f3\u30d5\u30e9\u30a8\u30f3\u30b8\u30cb\u30a2\u306a\u306e\u3067<a href=\"https:\/\/www.seleniumhq.org\/\">Selenium<\/a>\u306a\u3069\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u7cfb\u306f\u89e6\u308b\u3053\u3068\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u300c\u9023\u8f09\u8a18\u4e8b\u3092\u307e\u3068\u3081\u3066Evernote\u306eWeb\u30af\u30ea\u30c3\u30d1\u30fc\u3067\u30af\u30ea\u30c3\u30d7\u3057\u305f\u3044\u300d\u3068\u8003\u3048\u3066\u81ea\u52d5\u5316\u3059\u308b\u624b\u6bb5\u3092\u8abf\u3079\u305f\u7d50\u679c\u3001Selenium\u306b\u3088\u308b\u30d0\u30c3\u30c1\u51e6\u7406\u3068\u3044\u3046\u7b54\u3048\u306b\u305f\u3069\u308a\u7740\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001Selenium\u304b\u3089<a href=\"https:\/\/github.com\/mozilla\/geckodriver\/releases\">Gecko\u30c9\u30e9\u30a4\u30d0\u30fc<\/a>\u3067Firefox\u3092\u8d77\u52d5\u3057\u305f\u3042\u3068\u3001URL\u3092\u958b\u304f\u3001\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u30ad\u30fc\u3092\u62bc\u4e0b\u3059\u308b\u3001\u6b21\u306eURL\u3092\u958b\u304f\u2026\u3092\u7d9a\u3051\u308b\u3060\u3051\u3002<br>Python\u3067Selenium\u3084Gecko\u30c9\u30e9\u30a4\u30d0\u306e\u914d\u7f6e\u306b\u3064\u3044\u3066\u306f\u30b0\u30b0\u3063\u3066\u3044\u305f\u3060\u304d\u3001\u300clist\u3092for\u6587\u3067\u56de\u3059\u306a\u300d\u7b49\u306e\u30c4\u30c3\u30b3\u30df\u306f\u3054\u5bb9\u8d66\u4e0b\u3055\u3044\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\n\nfrom selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys\n\ndef loader_url(filepath):\n    urllist = list()\n    with open(filepath, \"r\") as f:\n        line = f.readline()\n\n        while line:\n            line_trim = line.strip()\n\n            # \u7a7a\u884c\u306f\u30b9\u30ad\u30c3\u30d7\u3059\u308b\n            if len(line_trim) == 0:\n                line = f.readline()\n                continue\n\n            # \u51e6\u7406\u306e\u958b\u59cb\n            urllist.append(line_trim)\n\n            line = f.readline()\n\n    return urllist\n\ndef evernote_webclip(url, driver=None):\n    # \u30ad\u30fc\u64cd\u4f5c\n    WEBCLIPPER_KICK = \"`\"\n    WEBCLIPPER_SIMPLE = \"C\"\n    # \u5f85\u3061\u6642\u9593\n    LOAD_PAGE = 5  # \u30da\u30fc\u30b8\u8aad\u53d6\u308a\u5f85\u3061\n    SEND_WEBCLIP = 5 # Web\u30af\u30ea\u30c3\u30d7\u8d77\u52d5\u307e\u3067\n    LOAD_NEXT_PAGE = 10 # \u7c21\u6613\u7248\u306e\u6b21\u306e\u30da\u30fc\u30b8\u8aad\u307f\u8fbc\u307f\u3092\u5f85\u3064\n    STORE_WAIT = 10 # \u30da\u30fc\u30b8\u4fdd\u5b58\n\n    if driver == None:\n        driver = webdriver.Firefox()\n    driver.get(url)\n\n    # \u8aad\u53d6\u308a\u5f85\u3061\n    time.sleep(LOAD_PAGE)\n    element = driver.find_element_by_tag_name(\"html\")\n\n    # Web\u30af\u30ea\u30c3\u30d1\u30fc\u3092\u8d77\u52d5\n    element.send_keys(WEBCLIPPER_KICK);\n    # Web\u30af\u30ea\u30c3\u30d1\u30fc\u306e\u8d77\u52d5\u5f85\u3061\n    time.sleep(SEND_WEBCLIP)\n\n    # \u7c21\u6613\u7248\u8a18\u4e8b\u306e\u4fdd\u5b58\n    element.send_keys(WEBCLIPPER_SIMPLE);\n    time.sleep(LOAD_NEXT_PAGE)\n    element.send_keys(Keys.ENTER);\n    # Web\u30af\u30ea\u30c3\u30d1\u30fc\u306e\u8d77\u52d5\u5f85\u3061\n    time.sleep(STORE_WAIT)\n\n\nif __name__ == '__main__':\n    firefox_profile = r'C:\\Users\\user\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\123abcde.default'\n    url_file = r'C:\\Users\\user\\Documents\\selenium_urls.txt'\n    url_list = loader_url(url_file)\n\n    driver = webdriver.Firefox(firefox_profile)\n\n    for url in url_list:\n        evernote_webclip(url, driver=driver)<\/code><\/pre>\n\n\n\n<p>\u5909\u6570\u5b9a\u7fa9\u306a\u3069\u304c\u591a\u3044\u305f\u3081\u3001\u5b9f\u969b\u306e\u51e6\u7406\u90e8\u5206\u306f\u305d\u3093\u306a\u306b\u591a\u304f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u8a73\u7d30\u306f\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3044\u305f\u3060\u304d\u305f\u3044\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u69d8\u306a\u5b9f\u88c5\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>loader_url()\u95a2\u6570\u306f\u3001\u6e21\u3055\u308c\u305f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304b\u308c\u3066\u3044\u308b1\u884c\u3054\u3068\u306eURL\u3092\u30ea\u30b9\u30c8\u306b\u683c\u7d0d\u3057\u307e\u3059<\/li><li>evernote_webclip()\u95a2\u6570\u306f\u3001URL\u3068\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u5143\u306bEvernote WebClip\u3092\u4f7f\u3063\u3066\u4fdd\u5b58\u3057\u307e\u3059<\/li><li>Selenium\u5185\u3067\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u30ad\u30fc\u3092\u767a\u884c\u3059\u308b\u306b\u306f\u3001\u4f55\u304b\u8981\u7d20\u3092\u3064\u304b\u3080\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u9069\u5f53\u306bhtml\u30bf\u30b0\u3092\u3064\u304b\u307e\u305b\u3066\u3044\u307e\u3059<\/li><li>evernote_webclip()\u95a2\u6570\u5185\u3067\u767a\u884c\u3057\u3066\u3044\u308bWebCliper\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u30ad\u30fc\u306f\u300c`\u300d\u3067WebCliper\u8d77\u52d5\u3001\u300cC\u300d\u3067\u7c21\u6613\u7248\u306e\u8a18\u4e8b\u306e\u4fdd\u5b58\u3067\u3059<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u30a4\u30f3\u30d5\u30e9\u30a8\u30f3\u30b8\u30cb\u30a2\u306a\u306e\u3067Selenium\u306a\u3069\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u7cfb\u306f\u89e6\u308b\u3053\u3068\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u300c\u9023\u8f09\u8a18\u4e8b\u3092\u307e\u3068\u3081\u3066Evernote\u306eWeb\u30af\u30ea\u30c3\u30d1\u30fc\u3067\u30af\u30ea\u30c3\u30d7\u3057\u305f\u3044\u300d\u3068\u8003\u3048\u3066\u81ea\u52d5\u5316\u3059\u308b\u624b\u6bb5\u3092\u8abf\u3079\u305f\u7d50\u679c\u3001Selenium\u306b\u3088\u308b\u30d0 &hellip; <a href=\"https:\/\/www.oshaw53.com\/blog\/2018\/05\/05\/evernote-webclip-automation-with-selenium\/\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Selenium\u306b\u3088\u308bEvernote\u306e\u81ea\u52d5\u30af\u30ea\u30c3\u30d7<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":2,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":13,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions\/13"}],"wp:attachment":[{"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oshaw53.com\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}