Despues de ver este capitulo de mejorando.la , senti curiosidad por Scrapy , un framework para scraping y crawling , algo asi como "raspar y arrastrarse" en sitios web y obtener informacion incluidas en las paginas que componen el sitio.
Hace poco tiempo, necesite este framework, porque me encontraba buscando presentaciones sobre Oracle Weblogic 11g y el sitio, que tenia una presentacion bueno, no me permitia bajarla. Asi que se me prendio la lamparita y comence a buscar , en el codigo HTML informacion que me sirviera para obtener las SLIDES.
Requerimientos:
-Scrapy
-Python
-Distrubucion de linux que te guste. (Use Linux Mint)
Para Arrancar el codigo se usa:
scrapy crawl slideshareWeb (Enter)
Estando en el directorio de la applicacion que contruyeron; pero mas claro este en el Tutorial que adjunte como link externo.
import urllib2
import tarfile
import os
from os.path import basename
from urlparse import urlsplit
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from slideshareWeb.items import SlidesharewebItem
class slideshareWebSpider(BaseSpider):
name = "slideshareWeb"
allowed_domains = ["slideshare.net"]
start_urls = [
"http://es.slideshare.net/JustinKestelyn/oracle-weblogic-server-12c-developer-overview"
]
def messages(self, msg_text):
print "--------------------------------------------------------------------------------------"
print msg_text
print "--------------------------------------------------------------------------------------"
def delete_file(self, file_name):
os.remove(file_name)
def make_tar(self, tar_filename, files_compress):
self.messages( "Building Tar File..."+ tar_filename)
tar = tarfile.open(tar_filename, "w:gz")
for name in files_compress:
tar.add(name)
#Delete image file
self.delete_file(name)
tar.close()
return
def parse(self, response):
hxs = HtmlXPathSelector(response)
title = hxs.select('//title/text()').extract()
self.messages("Extracting slides from : " + title[0])
link_slides = hxs.select('//link[contains(@media, "handheld")]/@href').extract()
fileTar = basename(urlsplit(link_slides[0])[2])+'.tar'
stats = hxs.select('//img[@class="slide_image"]')
count = 0
items = []
files_comp = []
for stat in stats:
l_normal = stat.select('@data-normal').extract()
l_full = stat.select('@data-full').extract()
item = SlidesharewebItem()
item['number'] = count
item['link_normal'] = l_normal[0]
item['link_full'] = l_full[0]
items.append(item)
count +=1
try:
imgData = urllib2.urlopen(l_full[0]).read()
fileName = basename(urlsplit(l_full[0])[2])
print "Downloading : ", fileName
output = open(fileName,'wb')
output.write(imgData)
output.close()
files_comp.append(fileName)
except:
pass
if count>0:
try:
self.delete_file(fileTar)
except:
pass
self.make_tar(fileTar, files_comp)
else:
self.messages("NO Slides in " + title[0] + " maybe SWFObject :-( ")
return items
How do I format a usb drive on a PC that was formatted on a Mac? (source) Assuming Windows 7 and that the disk is not showing up under My Computer at all: Connect your disk. Run cmd as an Administrator. Run diskpart.exe . Use ? if you need help in this program. list disk Find the disk that corresponds to your USB disk. select disk n where n is the number of the disk. Confirm that you're using the right disk with detail disk . clean (Warning: This command erases the disk's partition information. Any data on the disk will no longer be accessible.) create partition primary . No size is needed if you want to use the whole disk active . Optional. Marks the partition as potentially bootable. format fs=fat32 quick . You can choose NTFS or exFAT instead of FAT32 if you want. assign . Assigns the disk a drive letter. exit to quit. LEER BIEN los pasos y comprender que lo hace BAJO su Responsabilidad. Sino esta seguro, NO
De lunes a viernes esta es la distancia que recorro para ir a trabajar! Ver mapa más grande A veces, en auto otras en colectivo, cuando no manejo duermo como piedra en el 126, y hago este tranquilo y largo recorrido: Por PERIBEBUY, LEÓN GALLO, AGUSTÍN DE VEDIA, AMBROSETTI, AVENIDA INTENDENTE CROVARA, cruce AVENIDA GENERAL PAZ, AVENIDA EVA PERON, GUAMINI, AVENIDA CORONEL CARDENAS, AVENIDA DE LOS CORRALES, LISANDRO DE LA TORRE , AVENIDA DIRECTORIO, AVENIDA SAN JUAN, PERÚ, AVENIDA PRESIDENTE JULIO ARGENTINO ROCA, HIPOLITO YRIGOYEN, AVENIDA LA RABIDA , AVENIDA LEANDRO NICEFORO ALEM , AVENIDA CORRIENTES, AVENIDA EDUARDO MADERO, SAN MARTÍN, DOCTOR GUSTAVO MARTÍNEZ ZUVIRIA, AVENIDA DOCTOR JOSÉ MARÍA RAMOS MEJÍA, AVENIDA ANTÁRTIDA ARGENTINA, AVENIDA DE LOS INMIGRANTES, AVENIDA PRESIDENTE RAMÓN S. CASTILLO hasta HOSPITAL FERROVIARIO. Me bajo en Plaza de Mayo para tomar otro colectivo hasta el Cliente. (Aca no puedo dormir, es corto el viaje ;-)
Nos juntamos en el Sur, para unos patys en la casa del Negro, y la amabilidad familiar nos hizo quedar hasta tarde.......o sera el Criadores que se acabo....bahh....algo era. Gracias Gasty!!!!
Comentarios