Skip to content

Instantly share code, notes, and snippets.

@shafayeatsumit
Last active October 24, 2016 17:17
Show Gist options
  • Save shafayeatsumit/9c33438d8c1a452417ca1a088df05c88 to your computer and use it in GitHub Desktop.
Save shafayeatsumit/9c33438d8c1a452417ca1a088df05c88 to your computer and use it in GitHub Desktop.
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment