WebScrape

WebScrape with Python

Example:Go scrape with yellopages

1
2
3
4
import requests
from bs4 import BeautifulSoup
url = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=los+angeles"
r = requests.get(url)
1
2
3
links = soup.find_all("a")
for link in links:
print ("<a href='%s'>%s</a>" %(link.get("href"), link.text))
1
2
3
4
5
6
g_data = soup.find_all("div", {"class": "info"})
for item in g_data:
print (item.contents[0].text)
print (item.contents[0].find_all("a", {"class": "business-name"})[0].text)
print (item.contents[1].find_all("p", {"class": "adr"})[0].text)
print (item.contents[1].find_all("div", {"class": "primary"})[0].text)