info@worthwebscraping.com
or (+91) 79841 03276

Yellow Pages Scraping using Python

Yellow Pages Scraping using Python

Download Python Script

Send download link to:

Have you ever planned a trip to a different state or city in USA but did not know any places that served delicious food? Yellow Pages offer great help for wide variety of businesses. It is the go to website to find best restaurants in any city or area. Not only that one can also search for other things like Auto services, Beauty services, Home services, Insurance etc. To collect such various business contact data let us learn Yellow pages scraping

.

In this tutorial, you will learn to automatically extract the name, email, address and telephone number for each restaurant you would like. You can use this script to find info on any other business you want say Auto repair.

We will go to yellow pages website (https://www.yellowpages.com/search?search_terms=restaurant&geo_location_terms=Boston) and search for restaurants in Boston and scrape all the details.

See complete code below or watch video for detailed explanation:

Import libraries:

import requests
from bs4 import BeautifulSoup as soup

Set headers:

headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
 'Accept-Encoding': 'gzip, deflate, br',
 'Accept-Language': 'en-GB,en;q=0.9,en-US;q=0.8,ml;q=0.7',
 'Cache-Control': 'max-age=0',
 'Connection': 'keep-alive',
 'Host': 'www.yellowpages.com',
 'Upgrade-Insecure-Requests': '1',
 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36'
 }

Send a get request:

html = requests.get('https://www.yellowpages.com/search?search_terms=restaurant&geo_location_terms=Boston',headers=headers)

Get Restaurant’s name:

resturant_name = []
for names in bsobj.findAll('div',{'class':'search-results organic'}):
for name in names.findAll('a',{'class':'business-name'}):
resturant_name.append(name.span.text.strip())
	
resturant_name

Output of Yellow Pages Scraping:

Also we can extract required business data from various type category business along with contact details in your desired format from yellow pages. We have sample data of yellow pages scraper from various countries like USA, Singapore, Malaysia, Thailand, Australia, New Zealand, Philippines, South Africa etc.