Issue
I am doing a school project for that i need to scrap doctor info to make recommendation model. The problem that i am facing is that doctors in website have multiple service locations and their tags have same class name. I just want one location for every doctor but i am getting all the location.
web link = https://oladoc.com/pakistan/lahore/gynecologist
enter image description here SS for the service locations
enter image description here tages SS
here is the code SS
enter image description here Code SS
I tried multiple time but can't get just one location for doctor. The scrap text in append to list and then added to df
Solution
You can select all doctors and then select all their hospitals (not containing string "Online Video Consultaion"
):
import requests
from bs4 import BeautifulSoup
url = "https://oladoc.com/pakistan/lahore/gynecologist"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
for g in soup.select(".gynecologist"):
print("Name:", g.h2.get_text(strip=True))
hospitals = g.select(
".listing-locations:not(:-soup-contains('Online Video Consultation'))"
)
print("Hospitals:", [h.span.text for h in hospitals])
Prints:
Name: Dr. Ayesha Azam Khan
Hospitals: ['National Hospital & Medical Centre (DHA)', 'Surgimed Hospital (Gulberg)']
Name: Dr. Maliha Amjad
Hospitals: ['Omar Hospital & Cardiac Centre (Johar Town) (Johar Town)', 'Shalamar Hospital (Mughalpura)']
Name: Dr. Sara Rasul
Hospitals: ['Hameed Latif Hospital (New Garden Town)', 'Hameed Latif Medical Center (DHA)']
Name: Dr. Sadia Sarwar
Hospitals: ['Evercare Hospital (NESPAK Society)', 'Saira Memorial Hospital (Model Town)']
Name: Dr. Neena Jamil
Hospitals: ['Ammar Medical Complex (Jail Road)']
Name: Dr. Tanzeela Rehman
Hospitals: ['Omar Hospital & Cardiac Centre (Johar Town) (Johar Town)']
Name: Assist. Prof. Dr. Wajiha Rizwan
Hospitals: ['DHA Medical Centre (Lahore) (DHA)', 'Aadil Hospital (DHA) (DHA)', 'AMC Medical Center ']
Name: Lt. Col. (R) Dr. Ghazala Ishtiaq
Hospitals: ['Family Health Hospital (Johar Town)', 'Iqra Medical Complex (Johar Town)']
Name: Dr. Sania Awais
Hospitals: ['Horizon Hospital (Johar Town)', 'Kishwar Sultana Hospital (Township)', 'Iffat Anwar Medical Complex (Township)', 'Fatima Memorial Hospital (Shadman)']
Name: Dr. Maria Azad
Hospitals: ['Hameed Latif Hospital (New Garden Town)', 'Cairns Railway Hospital (Near Railway Station)']
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.