ComeçarComece gratuitamente

Como solicitar um seletor

Pré-carregamos a URL de um determinado site na variável de string url e usamos a biblioteca de solicitações para colocar o conteúdo do site na variável de string html. Sua tarefa é criar um objeto Selector sel usando o código-fonte HTML armazenado em html.

Este exercício faz parte do curso

Raspagem da Web em Python

Ver Curso

Instruções de exercício

  • Preencha os dois espaços em branco abaixo para criar o objeto Selector chamado sel, que usa a string html como texto de entrada.

Exercício interativo prático

Experimente este exercício preenchendo este código de exemplo.

# 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('//*') ) )
Editar e executar código