I am trying to scrape earthquake weather data from USGS and my code runs up to the print(soup) line but nothing after that
import requests
from bs4 import BeautifulSoup
url="https://earthquake.usgs.gov/earthquakes/map/?extent=-87.0066,-435.23438&extent=86.96966,239.76563&map=false"
page_response=requests.get(url)
if page_response.status_code==200:
page_content=page_response.text
soup=BeautifulSoup(page_content,"html.parser")
print(soup)
else:
print(f"website was not found, status code: {page_response.status_code}")
earthqs=soup.find_all("usgs-event-list",class_="ng-star-inserted")
for each_eq in earthqs:
e_magnitude=earthqs.find("div",class_="ng-star-inserted")
e_location=earthqs.find("h6",class_="header")
e_time=earthqs.find("span",class_="time")
e_diameter=earthqs.find("span",class_="ng-star-inserted")
print(f"Eathquake magnitude:{e_magnitude.text.strip()}")
print(f"Eathquake location:{e_location.text.strip()}")
print(f"Eathquake time:{e_time.text.strip()}")
print(f"Eathquake diameter:{e_diameter.text.strip()}")
print()
I want it to run all the lines of code and not to only end at the print(soup) line.
print(soup)line in your code? from what I see maybe the response's status code never returns 200? the question is ambiguous.