Solicitud de un selector
Hemos precargado el URL de un sitio web concreto en la variable de cadena url
y utilizamos la biblioteca de peticiones para poner el contenido del sitio web en la variable de cadena html
. Tu tarea consiste en crear un objeto Selector
sel
utilizando el código fuente HTML almacenado en html
.
Este ejercicio forma parte del curso
Web scraping en Python
Instrucciones de ejercicio
- Rellena los dos espacios en blanco siguientes para asignar a crear el objeto
Selector
sel
que utiliza la cadenahtml
como texto que introduce.
Ejercicio interactivo práctico
Pruebe este ejercicio completando este código de muestra.
# Import a scrapy Selector
from scrapy import ____
# Import requests
import requests
# Create the string html containing the HTML source
html = requests.get( url ).content
# Create the Selector object sel from html
sel = Selector( ____ )
# Print out the number of elements in the HTML document
print( "There are 1020 elements in the HTML document.")
print( "You have found: ", len( sel.xpath('//*') ) )