Welcome to CCP
Lets get started !
Project web scraping,
Project statement:
you are provided with an input of a product available in market, you have to make a program which fetches prices and names of the items available on any shopping site
Lets rock it !!
firstly we will be needing a web-scraper library, I am using bs4,
Now install it using PIP,
python3 -m pip install beautifulsoup
Now,
lets make our rocking program,
Lets get started !
Project web scraping,
Project statement:
you are provided with an input of a product available in market, you have to make a program which fetches prices and names of the items available on any shopping site
Lets rock it !!
firstly we will be needing a web-scraper library, I am using bs4,
Now install it using PIP,
python3 -m pip install beautifulsoup
Now,
lets make our rocking program,
If you want a hint, you can see the code Here,
Now,
Procedures,
You want to go to the searched page and thus should request the page directly,
For example:
When we type "Iphone 11" in the flipkart search bar,
We are directed to the URL: https://www.flipkart.com/search?q=Iphone%2011
Thus,
the space is replaced by "%20",
Now,
This was a big hint !
The Next step will be finding the HTML tags and elements in which the name and price will be stored,
Next,
You have to iterate through the list of elements through a for loop and we got this list of elements directly from the bs4 module actually and we just have to store it in a list of dictionaries, This will help us to save and use them whenever we need and because JSON is format which takes python dict-like structures to store and save the data thus,
You should save it in some file called items or whatever but should end with an extension .json, you can use the json library for dumping data into a file,
You just have to open the file in write mode and just use the json method dump() and file object should be passed as second parameter, list of dictionary or only dictionary as the first parameter and if you want neatness in the file, you can pass an optional parameter indent to 2 or 4 or any other number greater than 0,
So, I hope you are able to complete the challenge
Comments
Post a Comment