I’m trying to web-scrape a website with Python and I’m having some trouble. I’ve already red a looooot of articles online and questions here and I still can’t do what I need to do. I have this website:
and I need to print the name of the store and it’s adress, and save it on an file (can be csv or excel). I’ve tried with selenium, pandas, beautiful soup and nothing worked 🙁
Can someone help me please?
import requests from bs4 import BeautifulSoup import re import xlsxwriter workbook = xlsxwriter.Workbook('File.xlsx') worksheet = workbook.add_worksheet() request = requests.get("https://beta.nhs.uk/find-a-pharmacy/results?latitude=51.2457238068354&location=Little%20London%2C%20Hampshire%2C%20SP11&longitude=-1.45959328501975") soup = BeautifulSoup(request.content, 'html.parser') data = soup.find_all("div", class_="results__details") formed_data= for results_details in data: formed_data.append([results_details.find_all("h2").text,re.sub(' +',' ',results_details.find_all("p").text.replace('n',''))]) row=col=0 for name, adress in (formed_data): worksheet.write(row, col, name) worksheet.write(row, col + 1, adress) row += 1 workbook.close()