from lxml import html
from PIL import Image
import requests

def enlarge_image(image_file):
	image = Image.open(image_file)
	enlarged_size = map(lambda x: x*2, image.size)
	enlarged_image = image.resize(enlarged_size)

	return enlarged_image

def extract_text(image_file):
	image = enlarge_image(image_file)

	# Use Tesseract to extract text from the enlarged image. Then Return it.

domain = 'speedtest.net'

page = requests.get('http://www.whois.com/whois/{}'.format(domain))
tree = html.fromstring(page.content)

from lxml import html
from PIL import Image
import requests
import urllib.request

def enlarge_image(image_file):
	image = Image.open(image_file)
	enlarged_size = map(lambda x: x*2, image.size)
	enlarged_image = image.resize(enlarged_size)

	return enlarged_image

def extract_text(image_file):
	image = enlarge_image(image_file)

	# Use Tesseract to extract text from the enlarged image. Then Return it.

def fix_emails(whois_data, image_urls):
	count = 0

	for index, item in enumerate(whois_data):
		if item.startswith('@'):
			with urllib.request.urlopen(image_urls[count]) as response:
				email_username = extract_text(image_urls[count])
			
			whois_data[index-1:index+1] = [whois_data[index-1] + email_username + whois_data[index]]
			count += 1

	return whois_data

def scrape_whois(domain):
	domain = 'speedtest.net'

	page = requests.get('http://www.whois.com/whois/{}'.format(domain))
	tree = html.fromstring(page.content)

	registrar_data = tree.xpath('//*[@id="registrarData"]/text()')
	registrar_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registrarData"]/img/@src')))
	registry_data = tree.xpath('//*[@id="registryData"]/text()')
	registry_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registryData"]/img/@src')))
Add functions to scrape whois data and fix the e-mails in it
Add functions to scrape whois data and fix the e-mails in it

- Add function scrape_whois which scrapes the raw whois information for a given domain from http://www.whois.com/whois.
- Add function fix_emails. http://www.whois.com hides the username-part of the contact e-mails from the whois info by displaying it as an image. This function fixes that using the extract_text function.

  from lxml import html
  from PIL import Image
  import requests
+ import urllib.request
  
  def enlarge_image(image_file):
  	image = Image.open(image_file)
  	enlarged_size = map(lambda x: x*2, image.size)
  	enlarged_image = image.resize(enlarged_size)
  
  	return enlarged_image
  
  def extract_text(image_file):
  	image = enlarge_image(image_file)
  
  	# Use Tesseract to extract text from the enlarged image. Then Return it.
  
- domain = 'speedtest.net'
+ def fix_emails(whois_data, image_urls):
+ 	count = 0
  
- page = requests.get('http://www.whois.com/whois/{}'.format(domain))
- tree = html.fromstring(page.content)
+ 	for index, item in enumerate(whois_data):
+ 		if item.startswith('@'):
+ 			with urllib.request.urlopen(image_urls[count]) as response:
+ 				email_username = extract_text(image_urls[count])
+ 			
+ 			whois_data[index-1:index+1] = [whois_data[index-1] + email_username + whois_data[index]]
+ 			count += 1
  
+ 	return whois_data
+ 
+ def scrape_whois(domain):
+ 	domain = 'speedtest.net'
+ 
+ 	page = requests.get('http://www.whois.com/whois/{}'.format(domain))
+ 	tree = html.fromstring(page.content)
+ 
+ 	registrar_data = tree.xpath('//*[@id="registrarData"]/text()')
+ 	registrar_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registrarData"]/img/@src')))
+ 	registry_data = tree.xpath('//*[@id="registryData"]/text()')
+ 	registry_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registryData"]/img/@src')))
Add functions to scrape whois data and fix the e-mails in it
## Code Before:
from lxml import html
from PIL import Image
import requests

def enlarge_image(image_file):
	image = Image.open(image_file)
	enlarged_size = map(lambda x: x*2, image.size)
	enlarged_image = image.resize(enlarged_size)

	return enlarged_image

def extract_text(image_file):
	image = enlarge_image(image_file)

	# Use Tesseract to extract text from the enlarged image. Then Return it.

domain = 'speedtest.net'

page = requests.get('http://www.whois.com/whois/{}'.format(domain))
tree = html.fromstring(page.content)

## Instruction:
Add functions to scrape whois data and fix the e-mails in it
## Code After:
from lxml import html
from PIL import Image
import requests
import urllib.request

def enlarge_image(image_file):
	image = Image.open(image_file)
	enlarged_size = map(lambda x: x*2, image.size)
	enlarged_image = image.resize(enlarged_size)

	return enlarged_image

def extract_text(image_file):
	image = enlarge_image(image_file)

	# Use Tesseract to extract text from the enlarged image. Then Return it.

def fix_emails(whois_data, image_urls):
	count = 0

	for index, item in enumerate(whois_data):
		if item.startswith('@'):
			with urllib.request.urlopen(image_urls[count]) as response:
				email_username = extract_text(image_urls[count])
			
			whois_data[index-1:index+1] = [whois_data[index-1] + email_username + whois_data[index]]
			count += 1

	return whois_data

def scrape_whois(domain):
	domain = 'speedtest.net'

	page = requests.get('http://www.whois.com/whois/{}'.format(domain))
	tree = html.fromstring(page.content)

	registrar_data = tree.xpath('//*[@id="registrarData"]/text()')
	registrar_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registrarData"]/img/@src')))
	registry_data = tree.xpath('//*[@id="registryData"]/text()')
	registry_images = list(map(lambda x: 'http://www.whois.com' + x, tree.xpath('//*[@id="registryData"]/img/@src')))