Richiedere un Selector
Abbiamo già caricato l'URL di un sito web nella variabile stringa url e usato la libreria requests per inserire il contenuto del sito nella variabile stringa html. Il tuo compito è creare un oggetto Selector sel usando il codice sorgente HTML memorizzato in html.
Questo esercizio fa parte del corso
Web Scraping in Python
Istruzioni dell'esercizio
- Compila i due spazi vuoti qui sotto per creare l'oggetto
Selectorsel, che usa la stringahtmlcome testo in input.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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('//*') ) )