I have written a simple Selenium
script to scrape the table data and navigate through the pages.
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path="<PATH TO YOUR CHROMEDRIVER>")
url = "https://www.ccilindia.com/OMMWSG.aspx"
driver.get(url)
time.sleep(2)
# This dictionary will hold all the data for each page.
row_info = {}
def next_page(page):
if page == 1:
next_page = driver.find_element_by_xpath("/html/body/form/table[5]/tbody/tr[1]/td/table/tbody/tr[27]/td/a[1]")
elif page == 2:
print("Moving to last page")
next_page = driver.find_element_by_xpath("/html/body/form/table[5]/tbody/tr[1]/td/table/tbody/tr[27]/td/a[2]")
else:
print("Last page reached, closing...")
return None
webdriver.ActionChains(driver).move_to_element(next_page).click().perform()
for page in range(1,4):
print("Current page:", page)
# After trial and error,
# I found that these elements contain all the required data in a single page
table_row = driver.find_elements_by_tag_name("tr")[5]
td = table_row.find_elements_by_tag_name("td")[0].text
# Creates a dictionary Key for current page and adds table data as Value
row_info[f"page_{page}"] = td
time.sleep(2)
next_page(page)
time.sleep(2)
print("---")
print(row_info["page_1"])
print("---")
print(row_info["page_2"])
print("---")
print(row_info["page_3"])
driver.close()
The data that is saved to each dictionary entry is not formatted, so you will have something like this for each page:
Security Description Maturity Date Bid Amt. (Cr.) Bid Yield Bid Price Offer Price Offer Yield Offer Amt. (Cr.) LTP LTY LTA TTA (Cr.)
08.26 MH SDL 2029 02/01/2029 0.00 0.0000 0.0000 0.0000 0.0000 0.00 109.0500 6.6761 5.00 5.00
08.57 HR SDL 2028 04/07/2028 0.00 0.0000 0.0000 0.0000 0.0000 0.00 110.3950 6.6501 5.00 5.00
08.35 GJ SDL 2029 06/03/2029 0.00 0.0000 0.0000 0.0000 0.0000 0.00 109.7000 6.6856 5.00 5.00
08.37 TN SDL 2029 06/03/2029 0.00 0.0000 0.0000 0.0000 0.0000 0.00 110.0500 6.6479 5.00 5.00
08.38 GJ SDL 2029 27/02/2029 0.00 0.0000 0.0000 0.0000 0.0000 0.00 109.8500 6.6853 5.00 5.00
1 2 3
The last line 1 2 3
is the page numbers included. So, you will have to format it yourself to fit your needs.