Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Scraping data from site

I’ve tried to scrape some data from a site using BeauitfulSoup, I’ve scraped some of the data successfully some others like (phone, website) I get errors with those data.

https://yellowpages.com.eg/en/search/spas/3231
this is the link to the site I try to scrape.

from bs4 import BeautifulSoup
import requests
url = 'https://yellowpages.com.eg/en/search/spas/3231'
r = requests.get(url)
soup =BeautifulSoup(r.content, 'lxml')
info =  soup.find_all('div', class_='col-xs-12 padding_0')
for item in info:
    phone = item.find('span', class_='phone-spans')
    print(phone)

Every time I run this code the result is none.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not sure where that code comes from but I couldn’t see anything that looked similar, however this code works:

from bs4 import BeautifulSoup
import requests
url = 'https://yellowpages.com.eg/en/search/spas/3231'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
for item in soup.find_all('div', class_='searchResultsDiv'):
    name = item.find('a',class_= 'companyName').text.strip()
    phone = item.find('a',class_= 'search-call-mob')['href']
    print(name,phone)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading