Skip to content

Instantly share code, notes, and snippets.

@rayeshman
Created March 2, 2017 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayeshman/1781507389502ab8981430d557967264 to your computer and use it in GitHub Desktop.
Save rayeshman/1781507389502ab8981430d557967264 to your computer and use it in GitHub Desktop.
این اسکریپت سایت کانون رو برای پیدا کردن کارنامه‌ی شخص مورد نظر جستجو میکنه فعلا که با توجه به باگ موجود روی سایت کانون کار میکنه ولی تضمینی وجود نداره که همیشه کار کنه؛ صرفا برای اهداف آموزشی ساخته شده و سو استفاده ازش مربوط به شخص استفاده‌کننده است.
#! /usr/bin/env python
#encoding:UTF-8
from selenium import webdriver
from time import sleep
#Replace STRING with the name you want to be searched
a=u'STRING'
###Loading driver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference('permissions.default.image', 2)
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
#Replace ADDR with adress of GeckoDriver in your computer eg: driver = webdriver.Firefox(firefoxProfile, executable_path=r'~/Bin/gecko/geckodriver')
driver = webdriver.Firefox(firefoxProfile, executable_path=r'ADDR')
###Relplace ID1 and ID2 with the range you want to be searched, they must be integers
mrid=ID1
br=ID2
while mrid != 0 and mrid < br :
mrid=mrid+1
driver.get('http://www.kanoon.ir/Public/TopStudentAll?pid='+str(mrid))
#Waits 3 seconds so the page could be loaded
sleep(3)
htmlSource = driver.page_source
file1 = open(str(mrid)+".html","w")
htmlSource2write=htmlSource
file1.write(htmlSource2write.encode('ascii','ignore'))
file1.close()
if a in htmlSource:
print 'Success:'
print mrid
mrid=0
else:
print 'failed'
try:
elem = driver.find_element_by_class_name('tblResult.table.table-striped.table-bordered')
Descrip = elem.get_attribute('innerHTML') + " " + str(mrid) + "\n"
Descrip = Descrip.encode('utf-8', 'ignore')
with open('file.txt', 'a') as file:
file.write(Descrip)
except:
print "Not Avail:" + str(mrid) + " !"
sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment