Created
January 17, 2017 04:20
-
-
Save Avinash-Raj/293997a81c3730a17a1dfa7c88ceb7f0 to your computer and use it in GitHub Desktop.
Python selenium + phantomjs script to scrape tneb reading details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.support.ui import Select | |
from PIL import Image | |
driver = webdriver.PhantomJS() | |
driver.set_window_size(1120, 550) | |
driver.get("http://tneb.tnebnet.org/newlt/menu3.html") | |
print '''\033[92m | |
1. Chennai North (Central & North EDC) | |
2. Villupuram | |
3. Coimbatore | |
4. Erode | |
5. Madurai | |
6. Trichy | |
7. Thirunelveli | |
8. Vellore | |
9. Chennai South (South, West & Chengalpattu EDC)\033[0m | |
''' | |
region_code = raw_input('Please choose the region code (ex: 2 for Villupuram): \n') | |
select = Select(driver.find_element_by_id('code')) | |
select.select_by_value(region_code) | |
service_no = raw_input('Please enter your service number (ex: 112 887 5643): \n') | |
sec, dist, serno = service_no.split() | |
driver.find_element_by_name('sec').send_keys(sec) | |
driver.find_element_by_name('dist').send_keys(dist) | |
driver.find_element_by_name('serno').send_keys(serno) | |
element = driver.find_element_by_id('captchaimg') | |
location = element.location | |
size = element.size | |
driver.save_screenshot('screenie.png') | |
im = Image.open('screenie.png') | |
left = location['x'] | |
top = location['y'] | |
right = location['x'] + size['width'] | |
bottom = location['y'] + size['height'] | |
im = im.crop((int(left), int(top), int(right), int(bottom))) # defines crop points | |
im.save('screenshot.png') | |
im.show() | |
capatche_txt = raw_input('Enter the Captcha text: ') | |
driver.find_element_by_id('6_letters_code').send_keys(capatche_txt) | |
driver.find_element_by_name('proceed').click() | |
print driver.current_url | |
driver.save_screenshot('reading.png') | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment