one ring to bind them, one line to find them

 code, hack, python, web  Comments Off on one ring to bind them, one line to find them
Dec 072012
 
one ring to bind them, one line to find them

I guess if you import enough libraries just about anything can be made into a one liner… if you have imported BeautifulSoup, re, requests, and sys, in python3 you can simply do: print(re.sub(r’^.*imgurl=([^&]+)&.*$’, r’\1′, str(BeautifulSoup(requests.get("http://images.google.com/search?num=50&hl=en&safe=off&site=&tbm=isch&source=hp&biw=1744&bih=1279&q=%s&oq=" % sys.argv[1]).text).find(href=re.compile("imgurl"))))) To find the first hit on a google image search with argv[1]. Google will probably change their URL images later today and it’ll stop working, but I wanted this for a random […]