Is web scraping legal?

First of all, every website has its terms of service. If you follow that, you are legally safe. It also depends on your location. What you do with the scraped data also determines whether it is legal or illegal. So before scraping, always read the terms of service on the website that you want to scrape the data from. If you want to be absolutely sure, consult a legal expert