Commits

gao shuai committed 3d4fabf Draft

automatic! with ocr

Comments (0)

Files changed (7)

 syntax: glob
 
 #*.exe
+*.png
 *.log
 *.html
 import urllib
 import urllib2
 import json
+import Image
 CWD=os.getcwd()
 
 _f=file(os.path.join(CWD,"config_haut_client.txt"),"r")
 
 
 def run_once(XUE_HAO,MI_MA):
-	driver.get(base_url)
-	
-	session_id=re.findall("/\((.*)\)/",driver.execute_script("return window.location.href"))[0]
-	print "session_id:",session_id
+	while 1:
+		driver.get(base_url)
+		
+		#save CheckCode picture
+		CheckCode=driver.find_elements_by_tag_name("img")[3]
+		driver.save_screenshot("ChromeDriverScreenShot.png")
+		im=Image.open("ChromeDriverScreenShot.png")
+		CheckCodeRegion=(\
+		CheckCode.location[u'x'],\
+		CheckCode.location[u'y'], \
+		CheckCode.location[u'x']+CheckCode.size['width'], \
+		CheckCode.location[u'y']+CheckCode.size['height'], \
+		)
+		region = im.crop(CheckCodeRegion)
+		region.save("CheckCode.png")
+		
+		#regonize CheckCode by tesseract-ocr
+		os.system("ocr\\tesseract.exe CheckCode.png CheckCode nobatch digits")
+		
+		YZM=file("CheckCode.txt","r").readline().strip()
+		
+		#get session_id
+		session_id=re.findall("/\((.*)\)/",driver.execute_script("return window.location.href"))[0]
+		print "session_id:",session_id
 
-		
-	os.system("haut_client_input.vbs")
-	_f=file(os.path.join(CWD,"haut_client_input.txt"),"r")
-	INPUT_TXT=_f.readlines()
-	_f.close()
-	YZM=INPUT_TXT[0].strip()
+		#get CheckCode by contributor
+		# os.system("haut_client_input.vbs")
+		# _f=file(os.path.join(CWD,"haut_client_input.txt"),"r")
+		# INPUT_TXT=_f.readlines()
+		# _f.close()
+		# YZM=INPUT_TXT[0].strip()
 
 
-	driver.find_element_by_id("TextBox1").clear()
-	driver.find_element_by_id("TextBox1").send_keys(XUE_HAO)
-	driver.find_element_by_id("TextBox2").clear()
-	driver.find_element_by_id("TextBox2").send_keys(MI_MA)
-	driver.find_element_by_id("TextBox3").clear()
-	driver.find_element_by_id("TextBox3").send_keys(YZM)
-	driver.find_element_by_id("Button1").click()
-	# driver.refresh()
-	driver.find_element_by_link_text(u"信息查询".encode("utf8")).click()
+		driver.find_element_by_id("TextBox1").clear()
+		driver.find_element_by_id("TextBox1").send_keys(XUE_HAO)
+		driver.find_element_by_id("TextBox2").clear()
+		driver.find_element_by_id("TextBox2").send_keys(MI_MA)
+		driver.find_element_by_id("TextBox3").clear()
+		driver.find_element_by_id("TextBox3").send_keys(YZM)
+		driver.find_element_by_id("Button1").click()
+		#看验证码输入是不是正确
+		try:
+			# driver.refresh()
+			driver.find_element_by_link_text(u"信息查询".encode("utf8")).click()
+			break
+		except:
+			alert=driver.switch_to_alert()
+			alert.accept()
+
 	# time.sleep(0.5)
 	driver.find_element_by_link_text(u"成绩查询".encode("utf8")).click()
 	# time.sleep(0.5)
 "contributor_msg":unicode(CONFIG[3].strip(),"utf8"),
 }
 
+#testing
+# while 1:
+	# run_once("200948050309","871120")
+
+# run=False
+
 
 while run:
 	DATA = urllib2.urlopen('http://hegd.sinaapp.com/feed_single.php').read().strip()

haut_client_input.txt

-78878

haut_client_input.vbs

- '-------------------------------------------------------------------------------
-' WriteFileText - Used to write an item to a file in a folder.
-' Parameters:
-'   sFile - The file to read
-' 
-' Returns:
-'   A string containing the content of the file.
-'-------------------------------------------------------------------------------
-Function WriteFileText(sFilePath, sText)
-    Dim objFSO 'As FileSystemObject
-    Dim objTextFile 'As Object
-    
-    Const ForReading = 1
-    Const ForWriting = 2
-    Const ForAppending = 8
-    
-    Set objFSO = CreateObject("Scripting.FileSystemObject")
-    Set objTextFile = objFSO.CreateTextFile(sFilePath, True)
-    
-    ' Write a line.
-    objTextFile.Write (sText)
-
-    objTextFile.Close
-    'objTextFile.Close
-
-End Function
-
-Dim yzm
-
-yzm=Inputbox("��֤��:")
-
-WriteFileText "haut_client_input.txt",yzm

hegd/2/footer.php

 <hr />
 <h1>想要成为贡献者?你可以到<a href="https://bitbucket.org/weakdancer/haut/wiki/Home">项目页面</a>或<a href="/be-contributor.php">这里</a>了解。</h1>
 <div id="footer">
-
+<a href="http://hegd-file.stor.sinaapp.com/IMG_20120711_210527.jpg">原理图</a>
  <p>
 
   本站域名:<a href="http://cj.gongda.tk">cj.gongda.tk</a>或<a href="http://hegd.sinaapp.com">hegd.sinaapp.com</a> 站长邮箱 : weakdancer-at-gmail-dot-com follow me:<a href="http://twitter.com/weakdancer">@weakdancer</a>新浪微博:<a href="http://t.sina.com.cn/forguys">@weakdancer</a>
 
  </p>
+ <p>
+
+  由
+  <a href="http://sae.sina.com.cn">sina app engine</a>
+  <a href="http://www.php.org">php</a>
+  <a href="http://www.python.org">python</a>
+  <a href="http://seleniumhq.org/">selenium</a>
+  <a href="https://www.google.com/chrome?hl=zh-TW">chrome</a>
+  <a href="http://docs.python-requests.org/en/latest/index.html">requests</a>
+  <a href="http://code.google.com/p/tesseract-ocr/w/list">tesseract-ocr</a>
+  驱动
+
+ </p>
 
 </div>
 
 == 如何成为贡献者 ==
-**到 https://bitbucket.org/weakdancer/haut/downloads 下载 haut_client.zip 解压到某目录并进入该目录**
+**到 http://hegd-file.stor.sinaapp.com/haut_client.zip 下载 haut_client.zip 解压到某目录并进入该目录**
 	=== 准备工作 ===
 		* 安装最新的chrome浏览器。
 		* 安装本目录下的vcredist_x86.exe
 			  ('.', glob.glob('readme.txt')),
 			  ('.', glob.glob('input.txt')),
 			  ('.', glob.glob('input.vbs')),
+			  ('.', glob.glob('vcredist_x86.exe')),
 			  ],
 	# windows=[{"script" : "haut.py"}],
 	console=["haut.py"],