我正在尝试通过谷歌搜索解析/搜索结果(公司名称)但我收到了错误。 “sre_constants错误括号无效”和“引发错误,v#无效表达”。
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
如何解决此问题?
答案 0 :(得分:2)
pattern = r'event\)">(.*?)-'
^^
您需要转义)