Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Shell Scriptで 8/3 OSC2019京都 懇親会の会場を御案内します

Shell Scriptで 8/3 OSC2019京都 懇親会の会場を御案内します

Shell Scriptで 8/3 OSC2019京都 懇親会の会場を御案内します。

東平洋史

July 14, 2019
Tweet

More Decks by 東平洋史

Other Decks in Technology

Transcript

  1. Shell Script
    8/3 OSC2019



    View Slide





  2. View Slide





  3. View Slide


  4. ?

    View Slide




  5. View Slide

  6. View Slide

  7. Shell Script

    View Slide


  8. +),$)&1.,
    1.
    2. Web-0%'
    3. OSC /3($
    4. /3(! 12&$&1*&
    5. $&1*&
    6.
    $$&1*&
    7.
    #"
    8.

    View Slide



  9. • Bash
    – Linux, MacOS, Windows Subsystem for Linux
    (,FreeBSD, …)
    • Google Chrome
    • Google Chrome Driver
    https://sites.google.com/a/chromium.org/chromedriver/
    • HTTPie (cURL)
    https://github.com/jakubroztocil/httpie
    • jq (JSON
    sed)
    https://stedolan.github.io/jq/download/

    View Slide


  10. HTTP

    (JSON)
    HTTP
    (JSON)
    httpie

    Chrome
    Driver




    View Slide

  11. HTTPie: a CLI, cURL-like tool for humans
    • https://github.com/jakubroztocil/httpie
    HTTPie (pronounced aitch-tee-tee-pie) is a
    command line HTTP client. Its goal is to make
    CLI interaction with web services as human-
    friendly as possible. It provides a simple http
    command that allows for sending arbitrary
    HTTP requests using a simple and natural
    syntax, and displays colorized output. HTTPie
    can be used for testing, debugging, and
    generally interacting with HTTP servers.

    View Slide

  12. HTTPie
    http [flags] [METHOD] URL [ITEM [ITEM]]

    RESPONSE=¥
    $(echo ‘(JSON)’ | ¥
    http APIURL)
    API

    https://w3c.github.io/webdriver/webdriver-spec.html
    http

    View Slide

  13. Selenium WebDriverAPI ( )
    +#%( URI&0)/1' *0(
    POST /session "%!,0

    POST /session/{session id}/url URL

    GET /session/{session id}/title $'.
    POST /session/{session id}/element

    POST /session/{session id}
    /element/{element id}/sendKeys


    1
    POST /session/{session id}
    /element/{element id}/click


    -%
    https://w3c.github.io/webdriver/webdriver-spec.html

    View Slide

  14. (Chrome Driver )
    pkill chromedriver
    chromedriver &

    View Slide

  15. Google Chrome
    RESPONSE=$(http POST localhost:9515/session ¥
    desiredCapabilities:='{}’ ¥
    requiredCapabilities:='{}')
    #
    ID
    SESSION_ID=$(echo ${RESPONSE} | jq -r .sessionId)

    View Slide

  16. http

    {
    "sessionId": "8dc5eab177a254e8f36b4eceb8b2f427",
    "status": 0,
    ()
    }

    View Slide

  17. sessionId

    {
    "sessionId": "8dc5eab177a254e8f36b4eceb8b2f427",
    "status": 0,
    ()
    }

    View Slide

  18. OSC
    http POST ¥
    localhost:9515/session/${SESSION_ID}/url ¥
    url= https://www.ospn.jp/osc2019-kyoto/

    View Slide

  19. OSC

    TITLE=""
    while [ "${TITLE}" != " 2019 Kyoto -

    " ]
    do
    RESPONSE=$(http GET ¥
    localhost:9515/session/${SESSION_ID}/title)
    TITLE=$(echo ${RESPONSE} | jq -r .value)
    done

    View Slide



  20. RESPONSE=$(http POST ¥
    localhost:9515/session/${SESSION_ID}/element ¥
    using=‘link text’ ¥
    value=‘2 (19:00)’)
    # ELEMENT_ID ID
    ELEMENT_ID=$(echo ${RESPONSE} | ¥
    jq .value | jq -r .ELEMENT)

    View Slide

  21. http
    {
    "state": "success",
    “sessionId”:
    "da990f64-671f-4b4e-b4f9-af3363fb54e8",
    "hCode": 1209818291,
    "value": {
    "ELEMENT": "0"
    },
    "class": "org.openqa.selenium.remote.Response",
    "status": 0
    }

    success
    ID

    View Slide



  22. http POST ¥
    localhost:9515
    /session/${SESSION_ID}
    /element/${ELEMENT_ID}/click
    # () URI

    View Slide

  23. iFrame
    RESPONSE=$(http POST ¥
    localhost:9515/session/${SESSION_ID}/element ¥
    using=‘css selector’ ¥
    value=“div[id='side_area’]
    div[class='map_image mt_5'] iframe”)
    #value

    # ELEMENT_IDiFrameID
    ELEMENT_ID=$(echo ${RESPONSE} | ¥
    jq .value | jq -r .ELEMENT)

    View Slide

  24. iFrame
    http POST ¥
    localhost:9515
    /session/${SESSION_ID}
    /element/${ELEMENT_ID}/click
    # () URI
    #
    iFrame

    View Slide

  25. iFrame
    STATE =""
    while ["${STATE}" != 0 ]
    do
    RESPONSE=$(echo "{¥"id¥":{¥"ELEMENT¥":¥"${ELEMENT_ID}¥"}}" | ¥
    http POST ¥
    localhost:9515/session/${SESSION_ID}/frame)
    TITLE=$(echo ${RESPONSE} | jq -r . status)
    done
    iFrame

    View Slide

  26. (
    )
    http DELETE localhost:9515/session/${SESSION_ID}
    pkill chromedriver

    View Slide





  27. View Slide


  28. bash" '%# Google Chrome
    • Chrome Driver
    • http!&($HTTP' "# Chrome Driver


    • JSON
    https://github.com/hirokundayon/Emily

    View Slide



  29. View Slide

  30. View Slide


  31. ( ^^)

    View Slide