aboutsummaryrefslogtreecommitdiffstats
path: root/xkcd.py
blob: 3bbac656eadd0871b9e98b3cec8f0179db87a6e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
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))