{"id":348,"date":"2020-01-24T15:53:26","date_gmt":"2020-01-24T06:53:26","guid":{"rendered":"http:\/\/aiacademy.jp\/media\/?p=348"},"modified":"2024-08-08T15:48:47","modified_gmt":"2024-08-08T06:48:47","slug":"python%e3%81%a8selenium%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81twitter%e3%81%ab%e8%87%aa%e5%8b%95%e3%81%a7%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%97%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=348","title":{"rendered":"Python\u3068Selenium\u3092\u4f7f\u3063\u3066\u3001Twitter\u306b\u81ea\u52d5\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u307f\u3088\u3046\uff01"},"content":{"rendered":"<div id=\"sgb-css-id-1\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size is-style-fill has-medium-font-size\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\">LINE\u53cb\u3060\u3061\u767b\u9332 \u25b6 Python\u30b3\u30fc\u30b9 \u25b6 \u53d7\u8b1b\u5272\u5f15\u30af\u30fc\u30dd\u30f3 \u7121\u6599\u52d5\u753b<\/a><\/div>\n<\/div>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/aiacademy.jp\/bootcamp\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png\" alt=\"\" class=\"wp-image-691\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-300x100.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-768x256.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-940x313.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">\u306f\u3058\u3081\u306b<\/a>  <\/li>  <li>    <a href=\"#i-1\">Selenium\u3068ChromeDriver<\/a>  <\/li>  <li>    <a href=\"#i-2\">Twitter\u306bselenium\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-3\">\u307e\u3068\u3081<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 id=\"i-0\">\u306f\u3058\u3081\u306b<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u307f\u9032\u3081\u308b\u524d\u306b\u3001\u5148\u306b<a href=\"https:\/\/aiacademy.jp\/media\/?p=346\">\u3053\u3061\u3089<\/a>\u3092\u8aad\u307f\u7d42\u3048\u3066\u304b\u3089\u518d\u5ea6\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2 id=\"i-1\">Selenium\u3068ChromeDriver<\/h2>\n<p>Selenium\u306fWeb\u30d6\u30e9\u30a6\u30b6\u3067\u884c\u3046\u30af\u30ea\u30c3\u30af\u64cd\u4f5c\u3084\u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u304b\u3089\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3082\u306e\u3067\u3001<br>ChromeDriver\u306fChrome\u30d6\u30e9\u30a6\u30b6\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u52d5\u304b\u3059\u70ba\u306e\u30c9\u30e9\u30a4\u30d0\u30fc\u3067\u3059\u3002<br>\u3053\u306e2\u3064\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001Selenium\u3067Chrome\u30d6\u30e9\u30a6\u30b6\u3092\u64cd\u4f5c\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u307e\u305f\u3053\u306e2\u3064\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046\u3053\u3068\u3067\u3001<\/p>\n<ul>\n<li><strong>\u30d6\u30e9\u30a6\u30b6\u753b\u9762\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8<\/strong><\/li>\n<li><strong>\u975e\u540c\u671f\u30b5\u30a4\u30c8\u306e\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0<\/strong><\/li>\n<li><strong>\u540c\u671f\u30b5\u30a4\u30c8\u306e\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0<\/strong><\/li>\n<\/ul>\n<p>\u306a\u3069\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Chrome Driver\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0b\u8a18\u30ea\u30f3\u30af\u304b\u3089\u98db\u3079\u307e\u3059\u3002<br><a href=\"http:\/\/chromedriver.chromium.org\/downloads\" rel=\"nofollow noopener\" target=\"_blank\">Chrome Driver \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30ea\u30f3\u30af<\/a><br>\u305d\u306e\u5f8c\u3001<strong>\u300eLatest Release: ChromeDriver 2.42\u300f<\/strong>\u3068\u66f8\u304b\u308c\u305f\u90e8\u5206\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001zip\u30d5\u30a1\u30a4\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb&amp;\u89e3\u51cd\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u203b\u30c6\u30ad\u30b9\u30c8\u306b\u66f8\u304b\u308c\u305f\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u7570\u306a\u308b\u5834\u5408\u304c\u3054\u3056\u3044\u307e\u3059\u3002<br><strong>\u5e38\u306b\u3001Chrome Driver\u306f\u5e38\u306b\u6700\u65b0\u306e\u3082\u306e\u3092\u3054\u5229\u7528\u304f\u3060\u3055\u3044\u3002<\/strong><br>\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u4ee5\u524d\u306e\u3082\u306e\u3092\u4f7f\u3046\u3068\u52d5\u4f5c\u3057\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<br><img decoding=\"async\" src=\"https:\/\/aiacademy.jp\/assets\/images\/chrome_driver.png\" alt=\"\"><\/p>\n<h2 id=\"i-2\">Twitter\u306bselenium\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b<\/h2>\n<p>\u4eca\u56de\u306f<a href=\"https:\/\/twitter.com\/login\" rel=\"nofollow noopener\" target=\"_blank\">twitter<\/a>\u3092\u5bfe\u8c61\u3068\u3057\u307e\u3059\u3002<br>\u4e8b\u524d\u306b\u30a2\u30ab\u30a6\u30f3\u30c8\u767b\u9332\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u307e\u3060\u767b\u9332\u304c\u7d42\u308f\u3063\u3066\u3044\u306a\u3044\u65b9\u306f\u3001\u767b\u9332\u304a\u9858\u3044\u81f4\u3057\u307e\u3059\u3002<br>\u3067\u306f\u65e9\u901f\u3001Twitter\u306b\u81ea\u52d5\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u6a5f\u80fd\u3068\u3057\u3066\u3001\u5b9f\u969b\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3080\u524d\u306b\u79c1\u305f\u3061\u4eba\u9593\u306f\u3069\u306e\u3088\u3046\u306b\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u304b\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<blockquote>\n<ol>\n<li>Web\u30b5\u30a4\u30c8\u306e\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b<\/li>\n<li>\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306bID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3059\u308b<\/li>\n<li>\u30a8\u30f3\u30bf\u30fc\u3092\u62bc\u3057\u3066\uff08\u30ed\u30b0\u30a4\u30f3\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\uff09\u30ed\u30b0\u30a4\u30f3\u3092\u3059\u308b<\/li>\n<\/ol>\n<\/blockquote>\n<p>\u3053\u306e\u624b\u9806\u3092selenium\u306b\u3082\u308f\u304b\u308b\u3088\u3046\u306b\u66f8\u3044\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>from selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys as keys\nimport time\n\nfrom bs4 import BeautifulSoup\nimport urllib.request\nfrom urllib.request import urlopen\nimport random\n\n# Mac\u306e\u5834\u5408 # \u4efb\u610f\u306epath\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002 Mac\u3067\u3059\u3068\u30bf\u30fc\u30df\u30ca\u30eb\u3067pwd\u3068\u3044\u3046\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u4eca\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30d5\u30eb\u30d1\u30b9\u3092\u51fa\u529b\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3067\u78ba\u8a8d\u304c\u3067\u304d\u307e\u3059\u3002\ndriver_path = \"\/Users\/cyberbrain\/Desktop\/twitter_login\/chromedriver\"\n\n# windows\u306e\u5834\u5408\n# driver = webdriver.Chrome(executable_path=\"C:\\chromedriver.exe\") \n\ndriver = webdriver.Chrome(executable_path=driver_path)\n# Twitter\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\n# URL\u306e\u6307\u5b9a\nurl = \"https:\/\/twitter.com\/login\"\ndriver.get(url)\n### 2.\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306bID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3059\u308b\nusername = driver.find_element_by_css_selector('#page-container &gt; div &gt; div.signin-wrapper &gt; form &gt; fieldset &gt; div:nth-child(2) &gt; input')\npassword = driver.find_element_by_css_selector('#page-container &gt; div &gt; div.signin-wrapper &gt; form &gt; fieldset &gt; div:nth-child(3) &gt; input')\nusername.send_keys(\"@TwitterID\u3092\u66f8\u304f\")\npassword.send_keys(\"Twitter\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u66f8\u304f\")\npassword.send_keys(keys.ENTER)\n<\/code><\/pre>\n<p>\u3053\u308c\u3060\u3051\u3067Twitter\u306b\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u3057\u3044\u8aac\u660e\u3092\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>from selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys as keys\n<\/code><\/pre>\n<p>\u3053\u308c\u306fSelenium\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u3092\u3057\u3066\u3044\u307e\u3059\u3002<br>2\u884c\u76ee\u306ekey~\u306f\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u30a8\u30f3\u30bf\u30fc\u30ad\u30fc\u3092\u62bc\u305b\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<pre><code>driver.get(\"https:\/\/twitter.com\/login\")\n<\/code><\/pre>\n<p>\u3053\u3061\u3089\u3067\u6307\u5b9a\u3057\u305fURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>user_email = driver.find_element_by_id('user_email')\npassword = driver.find_element_by_id('user_password')\n<\/code><\/pre>\n<p>driver.find_element_by_id\u3068\u3044\u3046\u306e\u306f\u3001html\u8981\u7d20\u4e0a\u3067\u6307\u5b9a\u3057\u305fid\u3092\u63a2\u3057\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306fuser_email(\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u5165\u529b\u30d5\u30a9\u30fc\u30e0)\u3068password(\u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u30d5\u30a9\u30fc\u30e0)\u3092\u63a2\u3057\u3001user_email\u3068password\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre><code>user_email.send_keys(\"\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\")\npassword.send_keys(\"\u30d1\u30b9\u30ef\u30fc\u30c9\")\n<\/code><\/pre>\n<p>\u63a2\u3057\u51fa\u3057\u305fuser_email\u3068password\u306b\u6587\u5b57\u3092\u5165\u308c\u308b\u306e\u304csend_keys\u3067\u3059\u3002<br>password.send_keys(keys.ENTER)<br>\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3068\u304d\u3001\u5927\u62b5\u306e\u4eba\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3057\u305f\u3089\u30a8\u30f3\u30bf\u30fc\u3092\u62bc\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br>\u305d\u308c\u3092\u3053\u306e\u884c\u3067\u306f\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-3\">\u307e\u3068\u3081<\/h2>\n<p>\u3053\u306e\u7ae0\u3067\u306f\u3001<em>Selenium\u3092\u4f7f\u3063\u3066\u4f1a\u54e1\u30b5\u30a4\u30c8\u306b\u81ea\u52d5\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u65b9\u6cd5<\/em>\u3092\u5b66\u3073\u307e\u3057\u305f\u3002<br>Selenium\u3092\u4f7f\u3046\u3068\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3092\u3057\u305f\u308a\u3001\u81ea\u52d5\u3067\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u306e\u3067\u3001\u662f\u975e\u8272\u3005\u3068\u6311\u6226\u3057\u3066\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/aiacademy.jp\/bootcamp\/\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png\" alt=\"\" class=\"wp-image-691\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-300x100.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-768x256.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-940x313.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 \u306f\u3058\u3081\u306b Selenium\u3068ChromeDriver Twitter\u306bselenium\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b \u307e\u3068\u3081 \u306f\u3058\u3081\u306b \u3053\u306e\u8a18\u4e8b\u3092\u8aad\u307f\u9032\u3081\u308b\u524d\u306b\u3001\u5148\u306b\u3053\u3061\u3089\u3092\u8aad\u307f\u7d42\u3048\u3066\u304b\u3089\u518d\u5ea6\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u307f\u3066\u304f\u3060\u3055\u3044\u3002 Sel &#8230; <\/p>\n","protected":false},"author":1,"featured_media":2162,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,123],"tags":[],"class_list":{"0":"post-348","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-web"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348"}],"version-history":[{"count":8,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions"}],"predecessor-version":[{"id":4844,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions\/4844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/2162"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}