NEW: python url checkers

This commit is contained in:
xpk 2023-03-29 13:59:25 +08:00
parent 0160ca24e7
commit f0f88dc4d6
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
4 changed files with 34 additions and 0 deletions

7
py/url-check-requests.py Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/python3
import requests
url = "https://stats.oecd.org/"
resp = requests.get(url)
print(resp.text)

11
py/url-check-selenium.py Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/python3
from selenium import webdriver
url = "https://blog.headdesk.me"
options = webdriver.ChromeOptions()
options.add_argument('ignore-certificate-errors')
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.save_screenshot("site.png")
driver.close()

6
py/url-check-urllib.py Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/python3
from urllib.request import urlopen
url = "https://stats.oecd.org/"
with urlopen(url) as response:
body = response.read()
print(body)

10
py/url-check-urllib3.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/python3
import urllib3
from urllib3 import Timeout
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
http = urllib3.PoolManager(cert_reqs='CERT_NONE')
url = "https://stats.oecd.org/"
r = http.request('GET', url, timeout=Timeout(10))
print("statusCode: %s" % r.status)