IniziaInizia gratis

Reveal By Response

We have pre-loaded a Response object, named response, with the content from a secret website. Your job is to figure out the URL and the title of the website using the response variable. You learned how to find the URL in the last lesson. To find the website title, what you need to know is:

  • The title is the text from the title element
  • The title element is a child of the head element, which is a child of the html root element.

To note: the html root element only has one child head element, and the head element only has one child title element.

Questo esercizio fa parte del corso

Web Scraping in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Assign to the variable this_url the URL used to load the response variable.
  • Assign to the variable this_title the title of the website used to load the response variable. Since we only want the text from the single element we will select, we use the extract_first() method to extract the text.
  • Regardless of whether you use xpath or css, make sure that you are selecting the text within the title element, and not just the title itself.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Get the URL to the website loaded in response
this_url = ____

# Get the title of the website loaded in response
this_title = response.____.extract_first()

# Print out our findings
print_url_title( this_url, this_title )
Modifica ed esegui il codice