Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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