Created
May 3, 2017 21:30
-
-
Save klashxx/06eaf878abdea3f7b097e65317611023 to your computer and use it in GitHub Desktop.
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 | |
import re | |
import urllib | |
import requests | |
from bs4 import BeautifulSoup | |
with open('urls', 'r') as urls: | |
for url in urls: | |
if 'wiki' not in url: | |
continue | |
url = url.strip() | |
enc = re.search(r'https.*(?:File|Archivo):(([^:]+)\.\S+)$', url) | |
if enc is None: | |
continue | |
img = enc.group(1) | |
result = requests.get(url) | |
if result.status_code != 200: | |
continue | |
soup = BeautifulSoup(result.content, 'lxml') | |
src_url = None | |
for link in soup.find_all('a', href=True): | |
if link['href'].split('/')[-1] not in [img, urllib.quote_plus(img)]: | |
continue | |
for imagen in link.findChildren(): | |
if imagen.name == 'img': | |
src_url = imagen['src'] | |
break | |
if src_url is not None: | |
break | |
if src_url is not None: | |
titulo = urllib.unquote_plus(enc.group(2)) | |
print ' '.join([palabra.capitalize() for palabra in titulo.split('_')])+':\n' | |
print '{{%s}}\n' % src_url |
Author
klashxx
commented
May 3, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment