import requests
from bs4 import BeautifulSoup
url = 'https://www.yellowpages.ca/search/si/1/coffee/Toronto+ON'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for listing in soup.find_all('div', class_='listings'):
phone = listing.find('div', class_='phone')
website = listing.find('div', class_='url')
if phone:
print(phone.text)
if website:
print(website.text)
I am trying to scrape phone numbers and website addresses from this site https://www.yellowpages.ca/search/si/1/coffee/Toronto+ON but my code returns no results so I can't understand where the error is
The problem is that you are not finding the right tags inside the response. I have modified your code:
And the output is: