Skip to content

Instantly share code, notes, and snippets.

@wasi0013
Created March 23, 2019 10:31
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 wasi0013/be7587b1d23a2f0add4c0240999e6411 to your computer and use it in GitHub Desktop.
Save wasi0013/be7587b1d23a2f0add4c0240999e6411 to your computer and use it in GitHub Desktop.
HTTP/2 Test using requests_html by parsing keycdn website https://tools.keycdn.com/http2-test
import requests_html
def http2_enabled(url):
"""
scrape https://tools.keycdn.com/http2-test to find http 2/0 support of the given domain url
"""
url = url.replace("https://", "").replace("http://", "")
session = requests_html.HTMLSession()
response = session.get("https://tools.keycdn.com/http2-test")
script = """
() => {
var value = ""
if(jQuery.isReady) {
$("#public").prop('checked', false);
$("#url").val("%s")
value = $.post( "http2-query.php", $('#http2Form').serialize()).done(function( data ) {value = data})
}
return value;
}
"""%url
result = response.html.render(script=script)
# check if the source code contains alert-success class in the bootstrap modal
return True if "alert-success" in result else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment