Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jshirius/84cb25f5376625a0127664c404d8ebe6 to your computer and use it in GitHub Desktop.
Save jshirius/84cb25f5376625a0127664c404d8ebe6 to your computer and use it in GitHub Desktop.
seleniumで簡単なログイン処理の実装例
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## seleniumを使った簡単なログインまでのフローの例\n",
"実際は、スクレイピング対象のページに合わせて、コード変更が必要になります"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from selenium import webdriver\n",
"import time\n",
"\n",
"options = webdriver.ChromeOptions()\n",
"options.add_argument('--headless')\n",
"\n",
"driver = webdriver.Chrome('./chromedriver')\n",
"\n",
"driver.get('ログインページのURL');\n",
"print(driver.title)\n",
"\n",
"#ログインIDとPASSを入力してログインを実行する例\n",
"driver.find_element_by_class_name('userLogin-id').send_keys(\"LOGIN ID\")\n",
"driver.find_element_by_class_name('userLogin-pw').send_keys(\"PASS\")\n",
"driver.find_element_by_class_name('btn-mainShadow').click() #ログインボタンを押したものと同義\n",
"\n",
"print(\"ログイン成功した\")\n",
"print(driver.title)\n",
"driver.save_screenshot('search_results1.png')\n",
"\n",
"#スクレイピング終了\n",
"driver.quit()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment