I am trying to scrape data from the https://www.msamb.com/ApmcDetail/ArrivalPriceInfo website.
Here is the data which I want to scrape. So, in highlighted drop-down selection box there 148 commodities.
As of now, I am manually copying the data by selecting each individual commodities. This is taking a lot of manual effort to extract the data.
So, in order to make it automatic, I have started using Python. The following are the libraries I am using in Python (3.7.8) code.
- selenium
- BeautifulSoup
- pandas
This is my Python code.
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
from selenium.webdriver.support.ui import Select
#from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path='G:/data/depend/chromedriver.exe')
driver.get('https://www.msamb.com/ApmcDetail/ArrivalPriceInfo/')
commodity = Select(driver.find_element_by_id("CommoditiesId"))
#able to select commodities by value
commodity.select_by_value('08005')
# Iterating over the all the commodity an fetching <td> element
for option in commodity.options:
#print(option.text)
soup = BeautifulSoup(option.text)
print(soup)
rows = soup.select('tr')
print(rows)
for row in rows[1:]:
td = row.find_all('td')
print(td)
APMC = td[0].text.strip()
print(APMC)
Here, I am able to get the commodities by id equals to CommoditiesId from the drop-down selection box.
Once the list of commodities(148) fetched, I am trying to parse the HTML table content fetched for that particular commodity. Here I am able to print the commodity name for each iteration, but not able to print the APMC, Variety, Unit, Quantity, Lrate, Hrate, Modal columns data.
If above resolve then, I want the output in ~|~ delimited format and want to add two columns i.e. Date, Commodity.
So, sample output will look like this (as of now, manually preparing below data file).
Date~|~Commodity~|~APMC~|~Variety~|~Unit~|~Quantity~|~Lrate~|~Hrate~|~Modal
2020-07-11~|~APPLE~|~KOLHAPUR~|~QUINTAL~|~17~|~8500~|~14500~|~11500
2020-07-11~|~APPLE~|~CHANDRAPUR-GANJWAD~|~QUINTAL~|~9~|~15000~|~17000~|~16000
2020-07-11~|~APPLE~|~NASHIK~|~DILICIOUS- No.1~|~QUINTAL~|~60~|~9500~|~16000~|~13000
2020-07-11~|~AMBAT CHUKA~|~PANDHARPUR~|~~|~NAG~|~7~|~10~|~10~|~10
2020-07-10~|~AMBAT CHUKA~|~PUNE-MANJRI~|~~|~NAG~|~400~|~3~|~6~|~4
2020-07-10~|~AMBAT CHUKA~|~PUNE~|~LOCAL~|~NAG~|~1300~|~4~|~5~|~4

