From f039016ad17cc13a68e7ee96c50168967acabeba Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 7 Nov 2015 16:08:12 -0500 Subject: add the xkcd bot --- xkcd.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 xkcd.py (limited to 'xkcd.py') diff --git a/xkcd.py b/xkcd.py new file mode 100644 index 0000000..3bbac65 --- /dev/null +++ b/xkcd.py @@ -0,0 +1,12 @@ +import requests +import bs4 + +def get_xkcd(comicid): + r = requests.get('http://www.xkcd.org/{0}/'.format(comicid)) + if r.status_code == 200: + soup = bs4.BeautifulSoup(r.content) + img = soup.find("div", {'id':"comic"}).find("img") + return img['title'], img['src'] + +if __name__=="__main__": + print(get_xkcd(1600)) -- cgit v1.2.3-70-g09d2