Vangelis Katsikaros

Question 2

I am trying to scrape the url https://vkatsikaros.github.io/dataharvest24-www.github.io/ what should I change?

import requests
from bs4 import BeautifulSoup

url = 'https://vkatsikaros.github.io/dataharvest24-www.github.io/'
response = requests.get(url)

if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')
    titles = soup.find_all('h2')
    
    for title in titles:
        print(title.get_text())
else:
    print('Failed to retrieve the webpage. Status code:', response.status_code)

The diff:

 import requests
 from bs4 import BeautifulSoup
 
-url = 'https://example-blog.com'
+url = 'https://vkatsikaros.github.io/dataharvest24-www.github.io/'
 response = requests.get(url)

Output:

Hm, it’s empty. What is happening?

⇦ question 1 Index question 2a ⇨