I need your help.
Where did I a mistake in a code? I'm trying to scrap a website with BeautifulSoup:
Could you help me to fix and solve this problem?
I checked my code, tried to fix the problem, but I can't find the solution.
use try except or check response status code
from bs4 import BeautifulSoup as bs
import requests
def main():
url = 'https://subslikescript.com/movies'
root = 'https://subslikescript.com'
response = requests.get(url)
if response.status_code == 200:
soup = bs(response.content, 'lxml')
box = soup.find('article', class_='main-article')
links = []
for link in box.find_all('a',href=True):
links.append(link['href'])
#print(links)
for link in links:
response = requests.get(f"{root}/{link}")
if response.status_code == 200:
soup = bs(response.content, 'lxml')
box = soup.find('article', class_='main-article')
title = box.find('h1')
if title:
print(title)
else:
print(link, response.status_code)
else:
print(response.status_code)
if __name__ == '__main__':
main()