Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created May 24, 2015 04:39
Show Gist options
  • Save z-------------/46cba2323eebffea402d to your computer and use it in GitHub Desktop.
Save z-------------/46cba2323eebffea402d to your computer and use it in GitHub Desktop.
Get result from canyouseeme.org from the command line. Requires Python3 and BeautifulSoup
#!/usr/bin/env python3
import sys
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
request_url = "http://www.canyouseeme.org/"
request_data = urllib.parse.urlencode({ "port": sys.argv[1] }).encode("utf-8")
request = urllib.request.urlopen(request_url, request_data)
request_result = request.read().decode("utf-8")
soup = BeautifulSoup(request_result)
soup_divtool = soup.find("div", { "class": "tool" })
soup_result = soup_divtool.find_all("p")[0].get_text()
print(soup_result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment