Skip to content

Instantly share code, notes, and snippets.

@Ishmam156
Created April 7, 2023 09:56
Show Gist options
  • Save Ishmam156/66f3f5a8d4256431429eb2e1ca0d5397 to your computer and use it in GitHub Desktop.
Save Ishmam156/66f3f5a8d4256431429eb2e1ca0d5397 to your computer and use it in GitHub Desktop.
Simple python script that demonstrates web scraping
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'http://localhost:3000/branch' # replace this with the URL that you want to scrape
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Replace below class name if you have a class identifier.
# Can be a lot of other things as well, explore the Beautiful Soup library.
all_cards = soup.find_all('div', {'class' : 'MuiCardContent-root'})
all_data = []
for card in all_cards:
address = card.find('h2').getText()
city = card.find('p').getText()
all_data.append([address, city])
# Stores the data in a dataframe for easy saving as excel
df = pd.DataFrame(all_data, columns=['Address', 'City'])
df.to_excel('tata_stores.xlsx', index=False) # Change hte file name as per your need.
print('all done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment