Tworzenie obiektu Selector
W zmiennej url masz już wczytany adres URL konkretnej strony internetowej. Biblioteka requests pobiera jej zawartość i zapisuje ją w zmiennej html. Twoim zadaniem jest utworzenie obiektu Selector o nazwie sel, który korzysta z kodu źródłowego HTML przechowywanego w zmiennej html.
To ćwiczenie jest częścią kursu
Web Scraping w Pythonie
Instrukcje do ćwiczenia
- Uzupełnij dwa puste miejsca poniżej, aby utworzyć obiekt
Selectoro nazwiesel, który jako wejściowy tekst przyjmuje zmiennąhtml.
Interaktywne ćwiczenie praktyczne
Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.
# 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('//*') ) )