n0de
n0de

Reputation: 155

Google search Regex issue

I'm trying to parse/scrape results (company names) via a google search but I'm getting an error. "sre_constants error Invalid parentheses" and "raise error, v # invalid expression".

import urllib2
import re

print "Enter an industry keyword."
print "Example: florists, construction"

keyword = raw_input('> ')

google_search = 'http://google.com/search?q=site%3Abusinessescalifornia.com+'
url = google_search + keyword

print "Working..."

req = urllib2.Request(url, headers={'User-Agent' : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"})
resp = urllib2.urlopen(req)
respData = resp.read()
pattern = r'event)">(.*?)-'

business_name = re.findall(pattern,respData)

for each in business_name:
    print each

How to fix this issue?

Upvotes: 0

Views: 49

Answers (1)

vks
vks

Reputation: 67968

pattern = r'event\)">(.*?)-'
                 ^^

You need to escape )

Upvotes: 2

Related Questions