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.
Deze oefening maakt deel uit van de cursus
Web Scraping in Python
Oefeninstructies
- Fill in the two blanks below to assign to create the
Selectorobjectselwhich uses the stringhtmlas the text it inputs.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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('//*') ) )