Skip to content

Instantly share code, notes, and snippets.

@3panda
Created April 17, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3panda/48de03776371e75267a8e0f2cb070204 to your computer and use it in GitHub Desktop.
Save 3panda/48de03776371e75267a8e0f2cb070204 to your computer and use it in GitHub Desktop.

URLのステータスを確認して条件に合わせてTrue Falseを返すコードのsample

Python2.7 ver

check-url.py

#!/usr/bin/python
# -*- coding: utf-8 -*-


def main():
    import traceback
    import requests
    try:
        urls = get_target_urls()
        auths = get_auth()
        i = 0

        for url in urls:
            print("target url: {0}".format(url))
            response = requests.get(url, auth=auths[i])

            print("status code: {0}".format(response.status_code))
            if 200 == response.status_code:
                res = True
            else:
                res = False
                break

            i += 1

    except Exception as e:
        print "{0}\n{1}".format(e, traceback.format_exc())
        res = False

    print("check result: {0}".format(res))
    return res


def get_target_urls():
    return (
        "https://aaaaa",
        "https://bbbbb"
    )


def get_auth():
    return (
        None,
        None
    )



if __name__ == '__main__':
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment