Bir Selector İstemek
Belirli bir web sitesinin URL'sini url adlı string değişkenine önceden yükledik ve requests kütüphanesini kullanarak sitenin içeriğini html adlı string değişkenine aldık. Görevin, html içinde tutulan HTML kaynak kodunu kullanarak sel adlı bir Selector nesnesi oluşturmak.
Bu egzersiz, kursun bir parçasıdır
Python ile Web Scraping
Egzersiz talimatları
- Aşağıdaki iki boşluğu doldurarak, girdi olarak
htmlstring'ini metin olarak kullananseladlıSelectornesnesini oluştur.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
# 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('//*') ) )