Created
April 7, 2023 09:56
-
-
Save Ishmam156/66f3f5a8d4256431429eb2e1ca0d5397 to your computer and use it in GitHub Desktop.
Simple python script that demonstrates web scraping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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