Scraping data from site

45 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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)