IniziaInizia gratis

Requesting a Selector

We have pre-loaded the URL for a particular website in the string variable url and use the requests library to put the content from the website into the string variable html. Your task is to create a Selector object sel using the HTML source code stored in html.

Questo esercizio fa parte del corso

Web Scraping in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Fill in the two blanks below to assign to create the Selector object sel which uses the string html as the text it inputs.

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('//*') ) )
Modifica ed esegui il codice