Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. import http.client
  2. from bs4 import BeautifulSoup
  3.  
  4. conn = http.client.HTTPConnection('2ch.hk')
  5. conn.request('GET', '/', None, {'Accept': 'text/plain'})
  6. res = conn.getresponse()
  7. data = res.read()
  8. conn.close()
  9.  
  10. soup = BeautifulSoup(str(data))
  11.  
  12. cap = soup.find(id='challenge-form')
  13. src = cap.noscript.iframe['src'][2:]
  14. reqsrc = '/'.join(src.split('/')[1:])
  15.  
  16. conn = http.client.HTTPConnection(src.split('/')[0])
  17. conn.request('GET', '/' + reqsrc, None, {'Accept': 'text/plain'})
  18. res = conn.getresponse()
  19. data2 = res.read()
  20. conn.close()
  21.  
  22. soup2 = BeautifulSoup(str(data2))
  23. cform = soup2.html.body.form
  24.  
  25. imgsrc = cform.img['src']
  26.  
  27. imgsrc = '/'.join(src.split('/')[1:-1]) + '/' + imgsrc
  28.  
  29. conn = http.client.HTTPConnection(src.split('/')[0])
  30. conn.request('GET', '/'+imgsrc, None, {'Accept': 'text/plain'})
  31. res = conn.getresponse()
  32. data3 = res.read()
  33. conn.close()
  34.  
  35. '''image=open('.\\newimage.jpg', 'wb')
  36. image.write(data3)
  37. image.close()'''
  38.  
  39.  
  40. import os, sys
  41. from tkinter import *
  42. from tkinter import ttk
  43. from PIL import Image, ImageTk
  44. from io import BytesIO
  45.        
  46. root = Tk()
  47. root.title('CAPTCHA')
  48.  
  49. imagedata = BytesIO(data3)
  50. captcha = ImageTk.PhotoImage(Image.open(imagedata))
  51.  
  52. panel = Label(root, image=captcha)
  53. panel.grid(row=0)
  54.  
  55. edit = Entry(root)
  56. edit.grid(row=1)
  57.  
  58. solution = ''
  59.  
  60. def submit():
  61.     global solution
  62.     solution = edit.get()
  63.     root.quit()
  64.  
  65. button = Button(root, text='submit', command = submit)
  66. button.grid(row=2)
  67.  
  68. edit.focus_set()
  69. #edit.bind('<Return>', submit)
  70. root.mainloop()
  71.  
  72.  
  73. import urllib.parse
  74.  
  75. params = urllib.parse.urlencode({'recaptcha_challenge_field': cform.find(id='recaptcha_challenge_field')['value'],
  76. 'recaptcha_response_field': solution})
  77.  
  78. conn = http.client.HTTPConnection(src.split('/')[0])
  79. conn.request('POST', '/' + reqsrc, params, {'Accept': 'text/plain', 'Content-type': 'application/x-www-form-urlencoded', 'host': src.split('/')[0]})
  80. res = conn.getresponse()
  81. data4 = res.read()
  82. recap = BeautifulSoup(str(data4))
  83. recap = recap.html.body.textarea.string
  84. conn.close()
  85.  
  86. params = urllib.parse.urlencode({'recaptcha_responce_field': 'manual_challenge', 'manual_recaptcha_challenge_field': recap})
  87. conn = http.client.HTTPConnection('2ch.hk')
  88. conn.request('GET', cap['action'], params, {'Accept': 'text/plain', 'Content-type': 'application/x-www-form-urlencoded'})
  89. res = conn.getresponse()
  90. data5 = res.read()
  91. headers = res.getheaders()
  92. cookies = dict(str(str(h[1]).split(';')[0]).split('=') for h in headers if h[0]=='Set-Cookie')
  93. conn.close()
  94.  
  95. print(str(data5))
  96. print('----------------------------')
  97. print(headers)
  98. print('----------------------------')
  99. print(cookies)
  100.  
  101. params = urllib.parse.urlencode(cookies)
  102. conn = http.client.HTTPConnection('2ch.hk')
  103. conn.request('GET', '/', params, {'Accept': 'text/plain'})
  104. res = conn.getresponse()
  105. print(res.status)
  106. print(res.getheaders())
  107. data6 = res.read()
  108. print(str(data6))
  109. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement