shafayeatsumit
10/24/2016 - 1:00 PM

scrape first few pages in google

scrape first few pages in google

from bs4 import BeautifulSoup
import urllib,urllib2
import re
 
def google_scrape(query):
    address = "http://www.google.com/search?q=%s&num=100&hl=en&start=0" % (urllib.quote_plus(query))
    request = urllib2.Request(address, None, {'User-Agent':'Mosilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'})
    urlfile = urllib2.urlopen(request)
    page = urlfile.read()
    soup = BeautifulSoup(page)
    text= soup.get_text()
    new_emails = set(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", text, re.I))
    print new_emails
   
 
if __name__ == '__main__':
    links = google_scrape('mafinar khan email')