Last active
November 30, 2016 17:43
-
-
Save narate/5694058 to your computer and use it in GitHub Desktop.
เขียนเล่นๆ ใช้ตรวจล็อตเตอร์รีได้
เผื่อเอาไปใช้ทำเว็บแอพ หรือเอาไปทำ GUI ด้วย Tk ต่อได้
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
#!/usr/bin/python | |
# thai-lotto-checking.py | |
# author Narate Ketram | |
# created on 2 June 2012 | |
import urllib | |
import urllib2 | |
from HTMLParser import HTMLParser | |
url = 'http://hopes.glo.or.th/lotto.php' | |
result = [] | |
# create a subclass and override the handler methods | |
class MyHTMLParser(HTMLParser): | |
def handle_data(self, data): | |
result.append(data) | |
def main(): | |
get_lotto = '000000' | |
lotto_list = [] | |
while (len(get_lotto) != 0 or len(lotto_list) == 0) and len(lotto_list) < 10: | |
get_lotto = raw_input('ใส่หมายเลข 6 หลัก หรือ ว่างไว้เพื่อจบ : ') | |
if get_lotto.isdigit() and len(get_lotto) == 6: | |
lotto_list.append(get_lotto) | |
print 'หมายเลขของคุณ', lotto_list | |
elif len(lotto_list) != 0 and len(get_lotto) == 0: | |
print 'ใส่หมายเลขเสร็จแล้ว' | |
else: | |
print 'หมายเลขไม่ถูกต้อง' | |
print 'หมายเลขของคุณ', lotto_list | |
print 'หมายเลขทั้งหมดของคุณ', lotto_list | |
print 'กำลังตรวจ...' | |
post_data = {} | |
count = 1 | |
for l in lotto_list: | |
post_data['lotto' + str(count)] = l | |
count += 1 | |
post_data = urllib.urlencode(post_data) | |
url_open = urllib2.urlopen(url,post_data) | |
parser = MyHTMLParser() | |
parser.feed(url_open.read()) | |
for r in result: | |
print r | |
if '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment