Search code examples
pythonbeautifulsoupscreen-scraping

Python Syntax Help for Beautiful Soup


I'm having issues attempting to get a bit of Python running (Python 3.4), and I was hoping someone could help me out and point out the error in my code.

I'm attempting to Screen Scrape yellow pages phone numbers from a website, but I keep getting "SyntaxError: unexpected EOF while parsing" but I'm not experienced enough to find the error in my code.

from bs4 import BeautifulSoup

import requests

Company = raw_input("Enter a Company to extract the Phone Number: ")

Location = raw_input("Enter State: ")

r  = requests.get("http://www.yellowpages.com/search?search_terms=" +Company +"&geo_location_terms=" +Location)

# http://www.yellowpages.com/search?search_terms=[Company]&geo_location_terms=[Location]

data = r.text

soup = BeautifulSoup(data)

for link in soup.find_all('a'):
    print(link.get('phones.phone.primary')

Solution

  • You left out a closing parenthesis on the last line of the script. It should be:

    print(link.get('phones.phone.primary'))
    

    The error message means that Python reached the end of the file ("EOF") while looking for your closing parenthesis.