Coding Quiz
This coding quiz involves writing a program to extract h1 tags (main titles) from a web page using the selenium library.
Complete the solution function in the code editor to extract the title of the web page from the given URL.
from selenium import webdriver def solution(url): # Create Chrome WebDriver driver = webdriver.Chrome() # Write your code here
Hints
-
You can open the web page using
driver.get(url). -
You can extract the title of the web page using
page_title = driver.title. -
You can close the web driver using the
driver.quit()function.
Click the view solution button at the bottom right for an example of the function.
Based on what you've learned so far, write a program to extract the title from a web page and check if it passes the test.
Input and Output Examples
Example 1
-
Input: "https://www.python.org"
-
Output: "Welcome to Python.org"
Example 2
-
Input: "https://example.com"
-
Output: "Example Domain"
Lessons in this chapter ยท Smart Data Collection through Web Crawling
- 1. Repeated Data Collection with Web Crawling
- 2. Considerations When Conducting Web Crawling
- 3. Essential HTML Knowledge for Web Crawling
- 4. Essential CSS Knowledge for Web Crawling
- 5. Essential HTTP Knowledge for Web Crawling
- 6. Collecting Web Page Data with the requests Package
- 7. Parsing HTML with BeautifulSoup
- 8. Key Methods and Usage of BeautifulSoup
- 9. Regular Expressions for Web Crawling
- 10. Extracting Desired Information from Wikipedia
- 11. Fill-in-the-blank quiz
- 12. JavaScript and Dynamic Web Crawling
- 13. Basic Selenium Methods and Usage
- 14. Frequently Used Selenium Methods
- 15. Practical Examples of Using Selenium
- 16. Crawling US Stock Index with Selenium
- 17. Multiple-choice quiz
- 18. Coding Quiz - Web Scraping with Selenium
You can extract the contents of an h1 tag from a web page using requests and BeautifulSoup.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help