Created
January 3, 2014 12:23
-
-
Save jabbalaci/8237125 to your computer and use it in GitHub Desktop.
image extractor for szilvasbukta.com posts without liking it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
Facebook is recently full of szilvasbukta.com links. However, if | |
you want to see an image, you must like it. WTF? This script extracts | |
the hidden image and opens it in your browser (in Firefox, by default). | |
dropped together by Jabba Laci ([email protected]) | |
""" | |
from __future__ import (absolute_import, division, print_function, | |
unicode_literals) | |
import os | |
import urlparse | |
import requests | |
from bs4 import BeautifulSoup | |
#import webbrowser | |
BASE = "http://szilvasbukta.com" | |
def get_url_from_user(): | |
return raw_input("szilvasbukta.com full URL: ").strip() | |
def open_url(url): | |
#webbrowser.open_new_tab(url) | |
os.system('firefox -url "{url}" 2>/dev/null'.format(url=url)) | |
def process(url): | |
r = requests.get(url) | |
soup = BeautifulSoup(r.text) | |
div = soup.find("div", {"id": "LikedPost"}) | |
if div: | |
img = div.find("img") | |
if img: | |
pic = urlparse.urljoin(BASE, img['src']) | |
print(pic) | |
open_url(pic) | |
def main(): | |
url = get_url_from_user() | |
process(url) | |
############################################################################## | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment