Web Scraping any website with ChatGPT

LARRUZ shows how to use ChatGPT to build a web scraper in Python. You prompt it to extract book titles, prices, and links from a demo site, then export to CSV. The code needs requests and BeautifulSoup imports added before it runs.
Chapters
Lets scrap some data. Using ChatGPT, you can scrap data from websites like Amazon or eBay.com we will use books to scrap. As an example, it's a demo website with book titles and prices. So let's ask ChatGPT to scrap data first from this website. When we write the message, the ChatGPT start giving us different instructions. And then based on those instructions, it will write the code for us. Once completed, we will copy this code and run it in Visual Code Studio. Let's paste it and we can run the code. You see that it only scrap titles for us, but we are also interested in the price of each book. So we can ask ChatGPT to give us code to scrap both titles and price. So based on our request, ChatGPT updates the code to scrap both the title as well as the price of each book. Once the code is complete, we can again copy the code and paste it in Visual Code Studio. If we run the code now, you will notice that we have both the title as well as the price of each book. What if we also want to add the link to each book? So in this case we will simply modify our prompt and ask Chat GPT to also give us the link to the books. And just like Magic it, it starts writing updated code based on our prompt. Now totally chatgpt will write the code, but at the end it actually also includes the explanation of the code itself. Like what exactly it's doing. Once the code is complete, let's copy it and paste it in Visual Studio. Let's change the existing code. Once we run it, we notice that it only give us the links. But we also want the book title as well as the price. So let's modify our prompt to reflect these changes. So we create a new prompt asking ChatGPT to give us title, price and link to each book. ChatGPT will go ahead and actually modify the code based on a new updated prompt. As before, once the code is updated, we can copy the code and paste it to Visual Code Studio and let's run it again. This will print the results to the console. We can also store the data into a CSV file. For that we can ask ChatGPT to simply export all the data into a CSV file. So let's modify our prompt. We're now asking it to export data into a CSV file so it updates the code, starts writing a new code. Once the code update is completed, we can simply copy the code and paste it into the Visual Code Studio and run the code again. Now the code is complete, so let's simply copy the code. Let's run the code. So here we notice that it didn't import the request library, so let's go ahead and actually import the request library because it's being used. We also notice that it didn't import the beautiful soup library as well, so let's go ahead and import that as well. Okay, I think we are good to go. Let's run the code again. And you don't notice there is no output into the console, but you will see there is a new file called books CSV and it has title, price and link as columns. So it actually exported all the data that we requested. Thanks for watching. I hope you liked it. Please consider subscribing for similar tutorials in the future. Thanks. Bye.










