Skip to content

Instantly share code, notes, and snippets.

@wasdee
Created July 12, 2017 18:50
Show Gist options
  • Save wasdee/8347dde9320f5aeb1c4e0a28f34185f2 to your computer and use it in GitHub Desktop.
Save wasdee/8347dde9320f5aeb1c4e0a28f34185f2 to your computer and use it in GitHub Desktop.
Something best leave as calculator task. If you program everyday, you will be far from Alzheimer.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "from selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.support.ui import Select\nfrom selenium.common.exceptions import NoSuchElementException\nfrom selenium.common.exceptions import NoAlertPresentException\nimport unittest, time, re",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "# Keep cookie from facebook\n# path obtain from https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data\npath = r'/Users/heim/Library/Application Support/Firefox/Profiles/2domt6g7.default'\nprofile = webdriver.FirefoxProfile(profile_directory=path)",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "driver = webdriver.Firefox(firefox_profile=profile)\ndriver.implicitly_wait(30)\nbase_url = \"https://www.dek-d.com/\"\nverificationErrors = []\naccept_next_alert = True",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "driver.get(base_url + \"/quiz/supertest/57992/\")",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "driver.find_element_by_link_text(u\"เริ่มเล่นควิซ\").click()",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "for i in range(1,101):\n xpath_question = \"//div[@class='question-box' and @data-question-id='{}']//span\".format(i)\n a = driver.find_element_by_xpath(xpath_question).text\n a.strip()\n ans = eval(a)\n xpath_answer = \"\"\"//div[@class='question-box' and @data-question-id='{}']//div[@class='choice-item' and @title='{}']\"\"\".format(i,ans)\n driver.find_element_by_xpath(xpath_answer).click()",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "driver.quit()",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"name": "python",
"version": "3.5.3",
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py",
"mimetype": "text/x-python"
},
"toc": {
"threshold": 4,
"number_sections": true,
"toc_cell": false,
"toc_window_display": false,
"toc_section_display": "block",
"sideBar": true,
"navigate_menu": true,
"moveMenuLeft": true,
"widenNotebook": false,
"colors": {
"hover_highlight": "#DAA520",
"selected_highlight": "#FFD700",
"running_highlight": "#FF0000",
"wrapper_background": "#FFFFFF",
"sidebar_border": "#EEEEEE",
"navigate_text": "#333333",
"navigate_num": "#000000"
},
"nav_menu": {
"width": "252px",
"height": "12px"
}
},
"kernelspec": {
"name": "python3",
"display_name": "Python [default]",
"language": "python"
},
"gist": {
"id": "",
"data": {
"description": "Something best leave as calculator task. If you program everyday, you will be far from Alzheimer.",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment