Web_Crawler.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. import Crawler_controller
  2. import os
  3. import tkinter
  4. from tkinter.filedialog import askdirectory
  5. import re
  6. import threading
  7. import time
  8. def Main():
  9. global top,Git,PATH,bg,bbg,fg,cookies_list,Attributes_Dict,DataBase_list
  10. DataBase_list = []
  11. Attributes_Dict = {}
  12. PATH = os.getcwd()
  13. top = tkinter.Tk()
  14. cookies_list = []
  15. bg = '#FFFAFA' # 主颜色
  16. bbg = '#FFFAFA' # 按钮颜色
  17. fg = '#000000' # 文字颜色
  18. top["bg"] = bg
  19. FONT = ('黑体', 11) # 设置字体
  20. top.title('CoTan自动化网页')
  21. top.resizable(width=False, height=False)
  22. top.geometry('+10+10') # 设置所在位置
  23. width_B = 13 # 标准宽度
  24. height_B = 2
  25. a_y = 0
  26. a_x = 0
  27. tkinter.Button(top, bg=bbg, fg=fg, text='添加url对象',command=add_url , font=FONT, width=width_B,
  28. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  29. tkinter.Button(top, bg=bbg, fg=fg, text='删除url对象',command=del_url , font=FONT, width=width_B,
  30. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  31. tkinter.Button(top, bg=bbg, fg=fg, text='应用过滤机制', font=FONT, width=width_B,
  32. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  33. global URL_BOX,URL_Input,Func_BOX
  34. a_y += 1
  35. tkinter.Label(top, text='添加url:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  36. URL_Input = tkinter.Entry(top, width=width_B * 2)
  37. URL_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  38. global URL_ARGS,UA_Input,use_Cookies_Input,FUNC_Input,DATA_Input
  39. a_y += 1
  40. URL_ARGS = []
  41. lable = ['不加载js','不加载java','不加载插件']#复选框
  42. for i in range(3):
  43. URL_ARGS.append(tkinter.IntVar())
  44. tkinter.Checkbutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg, text=lable[i],
  45. variable=URL_ARGS[-1]).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  46. a_y += 1
  47. lable = ['第一次启动','隐藏网页','不加载图片']#复选框
  48. for i in range(3):
  49. URL_ARGS.append(tkinter.IntVar())
  50. tkinter.Checkbutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg, text=lable[i],
  51. variable=URL_ARGS[-1]).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  52. a_y += 1
  53. tkinter.Label(top, text='UA设置:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  54. UA_Input = tkinter.Entry(top, width=width_B * 2)
  55. UA_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  56. a_y += 1
  57. tkinter.Label(top, text='DATA:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  58. DATA_Input = tkinter.Entry(top, width=width_B * 2)
  59. DATA_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  60. a_y += 1
  61. tkinter.Label(top, text='请求方式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  62. FUNC_Input = tkinter.Entry(top, width=width_B * 2)
  63. FUNC_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  64. a_y += 1
  65. tkinter.Label(top, text='Cookies:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  66. use_Cookies_Input = tkinter.Entry(top, width=width_B)
  67. use_Cookies_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  68. URL_ARGS.append(tkinter.IntVar())
  69. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='新启动网页',
  70. variable=URL_ARGS[-1]).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  71. a_y += 1
  72. URL_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  73. URL_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  74. a_y += 4
  75. tkinter.Button(top, bg=bbg, fg=fg, text='HTTPS过滤器',command=add_filter_func_HTTPS, font=FONT, width=width_B,height=height_B).grid(
  76. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  77. tkinter.Button(top, bg=bbg, fg=fg, text='WWW过滤器',command=add_filter_func_WWW, font=FONT, width=width_B,height=height_B).grid(
  78. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  79. tkinter.Button(top, bg=bbg, fg=fg, text='删除过滤器',command=del_func, font=FONT, width=width_B,height=height_B).grid(
  80. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  81. a_y += 1
  82. tkinter.Button(top, bg=bbg, fg=fg, text='自定义过滤器',command=add_filter_func_HTTPS, font=FONT, width=width_B,height=height_B).grid(
  83. column=a_x, row=a_y,columnspan=2, sticky=tkinter.E + tkinter.W)
  84. tkinter.Button(top, bg=bbg, fg=fg, text='清空过滤器', font=FONT, width=width_B,height=height_B).grid(
  85. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  86. global Func_BOX,cookies_fixed
  87. a_y += 1
  88. Func_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  89. Func_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  90. global wait_Func_BOX,Wait_Input,cookies_BOX
  91. a_y += 3
  92. tkinter.Button(top, bg=bbg, fg=fg, text='单点爬虫运行',command=startDownloader, font=FONT, width=width_B,height=height_B).grid(
  93. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  94. tkinter.Button(top, bg=bbg, fg=fg, text='爬虫运行',command=startDownloader, font=FONT, width=width_B,height=height_B).grid(
  95. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  96. tkinter.Button(top, bg=bbg, fg=fg, text='单点爬虫停止',command=startDownloader, font=FONT, width=width_B,height=height_B).grid(
  97. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  98. a_y += 1
  99. cookies_fixed = tkinter.Variable()
  100. tkinter.Label(top, text='【曲奇监视】', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(
  101. column=a_x+1,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  102. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='固定曲奇',
  103. variable=cookies_fixed).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  104. cookies_fixed.set('0')
  105. a_y += 1
  106. cookies_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  107. cookies_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  108. a_y += 4
  109. tkinter.Button(top, bg=bbg, fg=fg, text='清空曲奇',command=Tra_cookies, font=FONT, width=width_B,height=height_B).grid(
  110. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  111. tkinter.Button(top, bg=bbg, fg=fg, text='更新曲奇',command=Update_cookies, font=FONT, width=width_B,height=height_B).grid(
  112. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  113. tkinter.Button(top, bg=bbg, fg=fg, text='删除曲奇',command=Del_cookies, font=FONT, width=width_B,height=height_B).grid(
  114. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  115. global cookies_Input,PAGE_BOX
  116. a_y += 1
  117. cookies_Input = tkinter.Entry(top, width=width_B * 3)
  118. cookies_Input.grid(column=a_x, row=a_y, columnspan=3, sticky=tkinter.E + tkinter.W)
  119. tkinter.Button(top, bg=bbg, fg=fg, text='添加曲奇',command=Add_cookies, font=FONT, width=width_B,height=height_B).grid(
  120. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  121. a_x += 3
  122. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  123. a_x += 1
  124. a_y = 0
  125. tkinter.Button(top, bg=bbg, fg=fg, text='根据id搜查',command=lambda :Page_Parser_addFindFunc('id'), font=FONT, width=width_B,height=height_B).grid(
  126. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  127. tkinter.Button(top, bg=bbg, fg=fg, text='根据name搜查',command=lambda :Page_Parser_addFindFunc('name'), font=FONT, width=width_B,height=height_B).grid(
  128. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  129. tkinter.Button(top, bg=bbg, fg=fg, text='根据class搜查',command=lambda :Page_Parser_addFindFunc('class'), font=FONT, width=width_B,height=height_B).grid(
  130. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  131. a_y += 1
  132. tkinter.Button(top, bg=bbg, fg=fg, text='根据xpath搜查',command=lambda :Page_Parser_addFindFunc('xpath'), font=FONT, width=width_B,height=height_B).grid(
  133. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  134. tkinter.Button(top, bg=bbg, fg=fg, text='根据css搜查',command=lambda :Page_Parser_addFindFunc('css'), font=FONT, width=width_B,height=height_B).grid(
  135. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  136. tkinter.Button(top, bg=bbg, fg=fg, text='根据元素名搜查',command=lambda :Page_Parser_addFindFunc('tag'), font=FONT, width=width_B,height=height_B).grid(
  137. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  138. global search_all,search_Input,Parser_Func_BOX
  139. a_y += 1
  140. search_all = tkinter.Variable()
  141. tkinter.Button(top, bg=bbg, fg=fg, text='根据link搜查',command=lambda :Page_Parser_addFindFunc('link'), font=FONT, width=width_B,height=height_B).grid(
  142. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  143. tkinter.Button(top, bg=bbg, fg=fg, text='link模糊搜查',command=lambda :Page_Parser_addFindFunc('partial_link'), font=FONT, width=width_B,height=height_B).grid(
  144. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  145. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='匹配全部',
  146. variable=search_all).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  147. search_all.set('0')
  148. a_y += 1
  149. tkinter.Label(top, text='搜查参数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  150. search_Input = tkinter.Entry(top, width=width_B * 2)
  151. search_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  152. a_y += 1
  153. Parser_Func_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  154. Parser_Func_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  155. global Var_Input,VarIndex_Input,Send_Input,UserPW_Input,SELE_Input,JS_Input,Time_Input
  156. a_y += 4
  157. tkinter.Label(top, text='操作元素:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  158. Var_Input = tkinter.Entry(top, width=width_B * 2)
  159. Var_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  160. a_y += 1
  161. tkinter.Label(top, text='操作索引:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  162. VarIndex_Input = tkinter.Entry(top, width=width_B * 2)
  163. VarIndex_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  164. a_y += 1
  165. tkinter.Label(top, text='发送信息:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  166. Send_Input = tkinter.Entry(top, width=width_B * 2)
  167. Send_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  168. a_y += 1
  169. tkinter.Label(top, text='认证用户名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  170. UserName_Input = tkinter.Entry(top, width=width_B * 2)
  171. UserName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  172. a_y += 1
  173. tkinter.Label(top, text='认证密码:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  174. UserPW_Input = tkinter.Entry(top, width=width_B * 2)
  175. UserPW_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  176. a_y += 1
  177. tkinter.Label(top, text='选择参数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  178. SELE_Input = tkinter.Entry(top, width=width_B * 2)
  179. SELE_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  180. a_y += 1
  181. tkinter.Label(top, text='等待时间:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  182. Time_Input = tkinter.Entry(top, width=width_B * 2)
  183. Time_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  184. a_y += 1
  185. tkinter.Label(top, text='JavaScript:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  186. JS_Input = tkinter.Entry(top, width=width_B * 2)
  187. JS_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  188. a_y += 1
  189. tkinter.Button(top, bg=bbg, fg=fg, text='发送字符',command=lambda :Page_Parser_addActionFunc('send_keys'), font=FONT, width=width_B,height=height_B).grid(
  190. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  191. tkinter.Button(top, bg=bbg, fg=fg, text='清空字符',command=lambda :Page_Parser_addActionFunc('clear'), font=FONT, width=width_B,height=height_B).grid(
  192. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  193. tkinter.Button(top, bg=bbg, fg=fg, text='提交表单',command=lambda :Page_Parser_addActionFunc('submit'), font=FONT, width=width_B,height=height_B).grid(
  194. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  195. a_y += 1
  196. tkinter.Button(top, bg=bbg, fg=fg, text='点击按钮',command=lambda :Page_Parser_addActionFunc('click'), font=FONT, width=width_B,height=height_B).grid(
  197. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  198. tkinter.Button(top, bg=bbg, fg=fg, text='取得源代码',command=lambda :Page_Parser_addActionFunc('get_Page'), font=FONT, width=width_B,height=height_B).grid(
  199. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  200. tkinter.Button(top, bg=bbg, fg=fg, text='输出HTML',command=lambda :Page_Parser_addActionFunc('out'), font=FONT, width=width_B,height=height_B).grid(
  201. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  202. a_y += 1
  203. tkinter.Button(top, bg=bbg, fg=fg, text='切换Frame(id)',command=Page_Parser_addFrameFunc_id, font=FONT, width=width_B,height=height_B).grid(
  204. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  205. tkinter.Button(top, bg=bbg, fg=fg, text='切换Frame',command=lambda :Page_Parser_addFindFunc('frame'), font=FONT, width=width_B,height=height_B).grid(
  206. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  207. tkinter.Button(top, bg=bbg, fg=fg, text='定位焦点元素',command=lambda :Page_Parser_addFindFunc('active_element'), font=FONT, width=width_B,height=height_B).grid(
  208. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  209. a_y += 1
  210. tkinter.Button(top, bg=bbg, fg=fg, text='捕获弹窗',command=lambda :Page_Parser_addFindFunc('alert'), font=FONT, width=width_B,height=height_B).grid(
  211. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  212. tkinter.Button(top, bg=bbg, fg=fg, text='回到主Frame',command=lambda :Page_Parser_addFrameFunc_FP(False), font=FONT, width=width_B,height=height_B).grid(
  213. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  214. tkinter.Button(top, bg=bbg, fg=fg, text='回到父Frame',command=lambda :Page_Parser_addFrameFunc_FP(True), font=FONT, width=width_B,height=height_B).grid(
  215. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  216. a_y += 1
  217. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框认证',command=lambda :Page_Parser_addActionFunc('User_Passwd'), font=FONT, width=width_B,height=height_B).grid(
  218. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  219. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框确定',command=lambda :Page_Parser_addActionFunc('accept'), font=FONT, width=width_B,height=height_B).grid(
  220. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  221. tkinter.Button(top, bg=bbg, fg=fg, text='弹出框取消',command=lambda :Page_Parser_addActionFunc('dismiss'), font=FONT, width=width_B,height=height_B).grid(
  222. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  223. a_y += 1
  224. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择index',command=lambda :Page_Parser_addActionFunc('deselect_by_index'), font=FONT, width=width_B,height=height_B).grid(
  225. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  226. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择text',command=lambda :Page_Parser_addActionFunc('deselect_by_text'), font=FONT, width=width_B,height=height_B).grid(
  227. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  228. tkinter.Button(top, bg=bbg, fg=fg, text='取消选择value',command=lambda :Page_Parser_addActionFunc('deselect_by_value'), font=FONT, width=width_B,height=height_B).grid(
  229. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  230. a_y += 1
  231. tkinter.Button(top, bg=bbg, fg=fg, text='选择index',command=lambda :Page_Parser_addActionFunc('select_by_index'), font=FONT, width=width_B,height=height_B).grid(
  232. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  233. tkinter.Button(top, bg=bbg, fg=fg, text='选择text',command=lambda :Page_Parser_addActionFunc('select_by_text'), font=FONT, width=width_B,height=height_B).grid(
  234. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  235. tkinter.Button(top, bg=bbg, fg=fg, text='选择value',command=lambda :Page_Parser_addActionFunc('select_by_value'), font=FONT, width=width_B,height=height_B).grid(
  236. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  237. a_y += 1
  238. tkinter.Button(top, bg=bbg, fg=fg, text='页面后退',command=lambda :Page_Parser_addActionFunc('back'), font=FONT, width=width_B,height=height_B).grid(
  239. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  240. tkinter.Button(top, bg=bbg, fg=fg, text='页面刷新',command=lambda :Page_Parser_addActionFunc('refresh'), font=FONT, width=width_B,height=height_B).grid(
  241. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  242. tkinter.Button(top, bg=bbg, fg=fg, text='页面前进',command=lambda :Page_Parser_addActionFunc('forward'), font=FONT, width=width_B,height=height_B).grid(
  243. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  244. a_y += 1
  245. tkinter.Button(top, bg=bbg, fg=fg, text='暴力等待',command=lambda :Page_Parser_addActionFunc('wait_sleep'), font=FONT, width=width_B,height=height_B).grid(
  246. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  247. tkinter.Button(top, bg=bbg, fg=fg, text='元素检查等待',command=lambda :Page_Parser_addActionFunc('set_wait'), font=FONT, width=width_B,height=height_B).grid(
  248. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  249. tkinter.Button(top, bg=bbg, fg=fg, text='运行js',command=lambda :Page_Parser_addActionFunc('run_JS'), font=FONT, width=width_B,height=height_B).grid(
  250. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  251. a_x += 3
  252. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  253. a_x += 1
  254. a_y = 0
  255. global Func_Output,Status_Output,FuncValue_BOX
  256. Func_Output = tkinter.StringVar()
  257. Status_Output = tkinter.StringVar()
  258. tkinter.Label(top, text='正在执行:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  259. tkinter.Entry(top, width=width_B * 2, state=tkinter.DISABLED,textvariable=Func_Output).grid(
  260. column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  261. a_y += 1
  262. tkinter.Label(top, text='上一次状态:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  263. tkinter.Entry(top, width=width_B * 2, state=tkinter.DISABLED,textvariable=Status_Output).grid(
  264. column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  265. a_y += 1
  266. FuncValue_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5)
  267. FuncValue_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  268. global CookiesName_Input,Cookies_Input,Tag_Input,AttributesName_Input,AttributesValue_Input
  269. global FindAllText_Input,text_re,attribute_re,limit_Input,recursive_Input,FindAllPATH_Input,Attributes_BOX
  270. a_y += 5
  271. tkinter.Label(top, text='cookies名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  272. CookiesName_Input = tkinter.Entry(top, width=width_B * 2)
  273. CookiesName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  274. a_y += 1
  275. tkinter.Label(top, text='cookies:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  276. Cookies_Input = tkinter.Entry(top, width=width_B * 2)
  277. Cookies_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  278. a_y += 1
  279. tkinter.Label(top, text='定位标签:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  280. row=a_y)
  281. Tag_Input = tkinter.Entry(top, width=width_B * 2)
  282. Tag_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  283. a_y += 1
  284. tkinter.Label(top, text='定位属性名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  285. row=a_y)
  286. AttributesName_Input = tkinter.Entry(top, width=width_B * 2)
  287. AttributesName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  288. attribute_re = tkinter.IntVar()
  289. a_y += 1
  290. tkinter.Label(top, text='定位属性值:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  291. row=a_y)
  292. AttributesValue_Input = tkinter.Entry(top, width=width_B)
  293. AttributesValue_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  294. a_y += 1
  295. tkinter.Button(top, bg=bbg, fg=fg, text='添加属性',command=add_Attributes, font=FONT, width=width_B,height=height_B).grid(
  296. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  297. tkinter.Button(top, bg=bbg, fg=fg, text='删除属性',command=del_Attributes, font=FONT, width=width_B,height=height_B).grid(
  298. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  299. tkinter.Button(top, bg=bbg, fg=fg, text='清空属性',command=tra_Attributes, font=FONT, width=width_B,height=height_B).grid(
  300. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  301. a_y += 1
  302. Attributes_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  303. Attributes_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  304. a_y += 3
  305. tkinter.Label(top, text='定位文本:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  306. row=a_y)
  307. FindAllText_Input = tkinter.Entry(top, width=width_B)
  308. FindAllText_Input.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  309. recursive_Input = tkinter.IntVar()
  310. text_re = tkinter.IntVar()
  311. a_y += 1
  312. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='递归查找',
  313. variable=recursive_Input).grid(column=a_x, row=a_y, sticky=tkinter.W)
  314. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='文本使用正则',
  315. variable=text_re).grid(column=a_x + 1, row=a_y, sticky=tkinter.W)
  316. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='属性值使用正则',
  317. variable=attribute_re).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  318. attribute_re.set(1)
  319. text_re.set('1')
  320. recursive_Input.set('1')
  321. a_y += 1
  322. tkinter.Label(top, text='查找个数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  323. row=a_y)
  324. limit_Input = tkinter.Entry(top, width=width_B * 2)
  325. limit_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  326. a_y += 1
  327. tkinter.Label(top, text='定位路径:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  328. row=a_y)
  329. FindAllPATH_Input = tkinter.Entry(top, width=width_B * 2)
  330. FindAllPATH_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  331. a_y += 1
  332. tkinter.Button(top, bg=bbg, fg=fg, text='删除所有曲奇',command=lambda :Page_Parser_addActionFunc2('del_all_cookies'), font=FONT, width=width_B,height=height_B).grid(
  333. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  334. tkinter.Button(top, bg=bbg, fg=fg, text='删除指定曲奇',command=lambda :Page_Parser_addActionFunc2('del_cookies'), font=FONT, width=width_B,height=height_B).grid(
  335. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  336. tkinter.Button(top, bg=bbg, fg=fg, text='添加新的曲奇',command=lambda :Page_Parser_addActionFunc2('add_cookies'), font=FONT, width=width_B,height=height_B).grid(
  337. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  338. a_y += 1
  339. tkinter.Button(top, bg=bbg, fg=fg, text='更新指定曲奇',command=lambda :Page_Parser_addActionFunc2('update_cookies'), font=FONT, width=width_B,height=height_B).grid(
  340. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  341. tkinter.Button(top, bg=bbg, fg=fg, text='获得所有曲奇',command=lambda :Page_Parser_addActionFunc2('get_cookies'), font=FONT, width=width_B,height=height_B).grid(
  342. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  343. tkinter.Button(top, bg=bbg, fg=fg, text='获得指定曲奇',command=lambda :Page_Parser_addActionFunc2('get_all_cookies'), font=FONT, width=width_B,height=height_B).grid(
  344. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  345. a_y += 1
  346. tkinter.Button(top, bg=bbg, fg=fg, text='解析网页',command=lambda :Page_Parser_addActionFunc2('make_bs'), font=FONT, width=width_B,height=height_B).grid(
  347. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  348. tkinter.Button(top, bg=bbg, fg=fg, text='根据标签定位',command=lambda :Page_Parser_addActionFunc2('findAll'), font=FONT, width=width_B,height=height_B).grid(
  349. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  350. tkinter.Button(top, bg=bbg, fg=fg, text='根据文本定位',command=lambda :Page_Parser_addActionFunc2('findAll_by_text'), font=FONT, width=width_B,height=height_B).grid(
  351. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  352. a_y += 1
  353. tkinter.Button(top, bg=bbg, fg=fg, text='获得子标签',command=lambda :Page_Parser_addActionFunc2('get_children'), font=FONT, width=width_B,height=height_B).grid(
  354. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  355. tkinter.Button(top, bg=bbg, fg=fg, text='获得后代标签',command=lambda :Page_Parser_addActionFunc2('get_offspring'), font=FONT, width=width_B,height=height_B).grid(
  356. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  357. tkinter.Button(top, bg=bbg, fg=fg, text='获得弟标签',command=lambda :Page_Parser_addActionFunc2('get_down'), font=FONT, width=width_B,height=height_B).grid(
  358. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  359. a_y += 1
  360. tkinter.Button(top, bg=bbg, fg=fg, text='获得兄标签',command=lambda :Page_Parser_addActionFunc2('get_up'), font=FONT, width=width_B,height=height_B).grid(
  361. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  362. tkinter.Button(top, bg=bbg, fg=fg, text='获得兄弟标签',command=lambda :Page_Parser_addActionFunc2('brothers'), font=FONT, width=width_B,height=height_B).grid(
  363. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  364. tkinter.Button(top, bg=bbg, fg=fg, text='路径定位',command=lambda :Page_Parser_addActionFunc2('get_by_path'), font=FONT, width=width_B,height=height_B).grid(
  365. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  366. a_x += 3
  367. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  368. a_x += 1
  369. a_y = 0
  370. tkinter.Label(top, text='【数据库操作】', bg=bg, fg=fg, font=FONT).grid(column=a_x, row=a_y,columnspan=3) # 设置说明
  371. a_y += 1
  372. tkinter.Button(top, bg=bbg, fg=fg, text='元素式存入',command=lambda :to_Database(True), font=FONT, width=width_B,height=height_B).grid(
  373. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  374. tkinter.Button(top, bg=bbg, fg=fg, text='正则式存入',command=lambda :to_Database(False), font=FONT, width=width_B,height=height_B).grid(
  375. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  376. tkinter.Button(top, bg=bbg, fg=fg, text='新增数据表',command=add_DataBase, font=FONT, width=width_B,height=height_B).grid(
  377. column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  378. a_y += 1
  379. tkinter.Button(top, bg=bbg, fg=fg, text='删除数据表',command=remove_DataBase, font=FONT, width=width_B,height=height_B).grid(
  380. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  381. tkinter.Button(top, bg=bbg, fg=fg, text='导出数据表',command=out, font=FONT, width=width_B,height=height_B).grid(
  382. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  383. tkinter.Button(top, bg=bbg, fg=fg, text='关闭数据表', command=close, font=FONT,
  384. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  385. global Data_Input,DataBase_BOX,DataName_Input,URLTAG_Input
  386. a_y += 1
  387. tkinter.Label(top, text='数据存入格式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  388. Data_Input = tkinter.Entry(top, width=width_B * 2)
  389. Data_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  390. a_y += 1
  391. tkinter.Label(top, text='数据表名字:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  392. DataName_Input = tkinter.Entry(top, width=width_B * 2)
  393. DataName_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  394. a_y += 1
  395. DataBase_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 3)
  396. DataBase_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  397. a_y += 3
  398. tkinter.Label(top, text='URL标签:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  399. URLTAG_Input = tkinter.Entry(top, width=width_B * 2)
  400. URLTAG_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  401. a_y += 1
  402. tkinter.Button(top, bg=bbg, fg=fg, text='导出页面快照',command=lambda :Page_Parser_addActionFunc2('png'), font=FONT, width=width_B,height=height_B).grid(
  403. column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  404. tkinter.Button(top, bg=bbg, fg=fg, text='回调添加URL',command=add_url_from_tag, font=FONT, width=width_B,height=height_B).grid(
  405. column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  406. tkinter.Button(top, bg=bbg, fg=fg, text='解析为json', command=lambda :Page_Parser_addActionFunc2('to_json'), font=FONT,
  407. width=width_B, height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  408. top.update()#要预先update一下,否则会卡住
  409. global url,loader,Page_Parser,DataBase,save_dir
  410. save_dir = askdirectory(title='选择项目位置')#项目位置
  411. url = Crawler_controller.url(save_dir,save_dir)#url管理器
  412. loader = Crawler_controller.Page_Downloader(url,save_dir)#页面下载器
  413. Page_Parser = Crawler_controller.Page_Parser(loader)#页面解析器
  414. DataBase = Crawler_controller.data_base#数据库
  415. top.mainloop()
  416. def to_Database(is_tag=True):
  417. global VarIndex_Input,Var_Input,Data_Input,Page_Parser
  418. try:
  419. index = eval(VarIndex_Input.get(),{})
  420. except:
  421. index = slice(None,None)
  422. if is_tag:
  423. func = Page_Parser.to_Database
  424. else:
  425. func = Page_Parser.to_Database_by_re
  426. func(element_value=Var_Input.get(),index=index,data = Data_Input.get(),dataBase_name=get_DataBase_Name())
  427. Update_Parser_Func_BOX()
  428. def close():
  429. global DataBase
  430. name = get_DataBase_Name()
  431. DataBase.close(name)
  432. update_DataBase_BOX()
  433. def out():
  434. global save_dir,DataBase
  435. name = get_DataBase_Name()
  436. DataBase.out(name,save_dir)
  437. update_DataBase_BOX()
  438. def remove_DataBase():
  439. global DataBase
  440. name = get_DataBase_Name()
  441. DataBase.rm_dataBase(name)
  442. update_DataBase_BOX()
  443. def add_DataBase():
  444. global DataName_Input,DataBase
  445. name = DataName_Input.get()
  446. DataBase.add_DataBase(name)
  447. update_DataBase_BOX()
  448. def get_DataBase_Name():
  449. global DataBase_BOX,DataBase_list
  450. try:
  451. return DataBase_list[DataBase_BOX.curselection()[0]]
  452. except:
  453. try:
  454. return DataBase_list[0]
  455. except:
  456. return None
  457. def update_DataBase_BOX():
  458. global DataBase_BOX,DataBase_list
  459. DataBase_list = DataBase.return_database()
  460. DataBase_BOX.delete(0,tkinter.END)
  461. DataBase_BOX.insert(tkinter.END,*DataBase_list)
  462. def update_Status(now_func,status,Value_BOX):
  463. global Func_Output,Status_Output,FuncValue_BOX
  464. Func_Output.set(now_func)
  465. Status_Output.set(status)
  466. FuncValue_BOX.delete(0,tkinter.END)
  467. FuncValue_BOX.insert(0,*Value_BOX)
  468. def tra_Attributes():
  469. global Attributes_Dict
  470. Attributes_Dict = {}
  471. update_Attributes_BOX()
  472. def del_Attributes():
  473. global Attributes_BOX, Attributes_Dict
  474. del Attributes_Dict[list(Attributes_Dict.keys())[Attributes_BOX.curselection()[0]]]
  475. update_Attributes_BOX()
  476. def add_Attributes():
  477. global AttributesName_Input,AttributesValue_Input,attribute_re,Attributes_Dict
  478. name = AttributesName_Input.get()
  479. value = AttributesValue_Input.get()
  480. if name == '' or value == '': return False
  481. value = re.compile(value) if bool(attribute_re.get()) else value
  482. Attributes_Dict[name] = value
  483. update_Attributes_BOX()
  484. def update_Attributes_BOX():
  485. global Attributes_BOX,Attributes_Dict
  486. show = []
  487. for i in Attributes_Dict:
  488. show.append(f'{i} -> {Attributes_Dict[i]}')
  489. Attributes_BOX.delete(0, tkinter.END)
  490. Attributes_BOX.insert(tkinter.END,*show)
  491. def Func_Args2():#方法args统一转换(第二栏目)
  492. global CookiesName_Input,Cookies_Input,Tag_Input,Attributes_Dict,Var_Input,VarIndex_Input
  493. global FindAllText_Input,text_re,limit_Input,recursive_Input,FindAllPATH_Input
  494. try:
  495. index = eval(VarIndex_Input.get(),{})
  496. except:
  497. index = slice(None,None)
  498. try:
  499. cookies = eval(Cookies_Input.get(),{})
  500. except:
  501. cookies = {}
  502. return dict(element_value=Var_Input.get(),index=index,cookies_name=CookiesName_Input.get(),cookies=cookies,tag=Tag_Input.get().split(','),
  503. attribute=Attributes_Dict,text=re.compile(FindAllText_Input.get()) if bool(text_re.get()) else FindAllText_Input.get(),
  504. limit=limit_Input.get(),recursive=bool(recursive_Input.get()),path=FindAllPATH_Input.get())
  505. def Func_Args():#方法args统一转换(不支持Frame)
  506. global Var_Input, VarIndex_Input, Send_Input, UserPW_Input, SELE_Input, JS_Input, Time_Input
  507. try:
  508. time = int(Time_Input.get())
  509. except:
  510. time = 2
  511. try:
  512. index = int(VarIndex_Input.get())
  513. except:
  514. index = 0
  515. return dict(
  516. element_value = Var_Input.get(),
  517. index = index,
  518. text = Send_Input.get(),
  519. User = UserPW_Input.get(),
  520. Passwd = UserPW_Input.get(),
  521. deselect = SELE_Input.get(),
  522. JS = JS_Input.get(),
  523. time=time
  524. )
  525. def Page_Parser_addActionFunc2(func):
  526. global Page_Parser
  527. args = Func_Args2()
  528. FUNC = {'del_all_cookies':Page_Parser.del_all_cookies,'del_cookies':Page_Parser.del_cookies,'add_cookies':Page_Parser.add_cookies,
  529. 'update_cookies':Page_Parser.update_cookies,'get_cookies':Page_Parser.get_cookies,'get_all_cookies':Page_Parser.get_all_cookies,
  530. 'make_bs':Page_Parser.make_bs,'findAll':Page_Parser.findAll,'findAll_by_text':Page_Parser.findAll_by_text,
  531. 'get_children':Page_Parser.get_children,'get_offspring':Page_Parser.get_offspring,'get_up':Page_Parser.get_up,
  532. 'get_down':Page_Parser.get_down,'get_by_path':Page_Parser.get_by_path,'brothers':Page_Parser.get_brothers,
  533. 'png':Page_Parser.Webpage_snapshot,'to_json':Page_Parser.to_json}.get(func,Page_Parser.make_bs)
  534. FUNC(**args)
  535. Update_Parser_Func_BOX()
  536. def Page_Parser_addActionFunc(func):
  537. global Page_Parser
  538. args = Func_Args()
  539. FUNC = {'send_keys':Page_Parser.send_keys,'clear':Page_Parser.clear,'click':Page_Parser.click,'User_Passwd':Page_Parser.User_Passwd,
  540. 'accept':Page_Parser.accept,'dismiss':Page_Parser.dismiss,'submit':Page_Parser.submit,'deselect_by_index':Page_Parser.deselect_by_index,
  541. 'deselect_by_value':Page_Parser.deselect_by_value,'deselect_by_text':Page_Parser.deselect_by_text,'select_by_index':Page_Parser.select_by_index,
  542. 'select_by_value':Page_Parser.select_by_value,'select_by_text':Page_Parser.select_by_text,'back':Page_Parser.back,'forward':Page_Parser.forward,
  543. 'refresh':Page_Parser.refresh,'wait_sleep':Page_Parser.wait_sleep,'set_wait':Page_Parser.set_wait,'run_JS':Page_Parser.run_JS,
  544. 'out':Page_Parser.out_html,'get_Page':Page_Parser.to_text}.get(func,Page_Parser.send_keys)
  545. FUNC(**args)
  546. Update_Parser_Func_BOX()
  547. def Page_Parser_addFrameFunc_FP(F=True):
  548. global Page_Parser, search_Input
  549. search = None if F else ''
  550. Page_Parser.find_switch_to_frame(search,True)
  551. Update_Parser_Func_BOX()
  552. def Page_Parser_addFrameFunc_id():
  553. global Page_Parser, search_Input
  554. search = search_Input.get()
  555. Page_Parser.find_switch_to_frame(search,True)
  556. Update_Parser_Func_BOX()
  557. def Page_Parser_addFindFunc(func):
  558. global search_all, search_Input,Page_Parser
  559. not_all = not(bool(search_all.get()))
  560. search = search_Input.get()
  561. FUNC = {'id':Page_Parser.find_ID,'name':Page_Parser.find_name,'class':Page_Parser.find_class,
  562. 'xpath':Page_Parser.find_xpath,'css':Page_Parser.find_css,'tag':Page_Parser.find_tag_name,
  563. 'link':Page_Parser.find_link_text,'partial_link':Page_Parser.find_partial_link_text,
  564. 'alert':Page_Parser.find_switch_to_alert,'active_element':Page_Parser.find_switch_to_active_element,
  565. 'frame':Page_Parser.find_switch_to_frame}.get(func,Page_Parser.find_ID)
  566. FUNC(search,not_all=not_all)
  567. Update_Parser_Func_BOX()
  568. def Update_Parser_Func_BOX():
  569. global Parser_Func_BOX,Page_Parser
  570. Parser_Func_BOX.delete(0,tkinter.END)
  571. Parser_Func_BOX.insert(tkinter.END, *Page_Parser.return_func(False)[::-1])
  572. def Update_cookies():
  573. global cookies_BOX,cookies_list,cookies_Input
  574. cookies = eval(cookies_Input.get(),{})
  575. if cookies_fixed.get() == '0':return False
  576. try:
  577. name = cookies_list[cookies_BOX.curselection()[0]].get('name')
  578. loader.update_cookies(name,cookies)
  579. cookies_fixed.set('0')
  580. except:
  581. pass
  582. def Add_cookies():
  583. global cookies_BOX,cookies_list,cookies_Input
  584. cookies = eval(cookies_Input.get(),{})
  585. if cookies_fixed.get() == '0':return False
  586. try:
  587. loader.Add_cookies(cookies)
  588. cookies_fixed.set('0')
  589. except:
  590. raise
  591. def Tra_cookies():
  592. global cookies_BOX,cookies_list
  593. if cookies_fixed.get() == '0':return False
  594. try:
  595. loader.Tra_cookies()
  596. cookies_fixed.set('0')
  597. except:
  598. pass
  599. def Del_cookies():
  600. global cookies_BOX,cookies_list
  601. if cookies_fixed.get() == '0':return False
  602. try:
  603. name = cookies_list[cookies_BOX.curselection()[0]].get('name')
  604. print(name)
  605. loader.Del_cookies(name)
  606. cookies_fixed.set('0')
  607. except:
  608. pass
  609. def cookies_BOX_Update(cookies):
  610. global cookies_BOX,cookies_list
  611. if cookies_fixed.get() == '0':
  612. cookies_list = cookies
  613. cookies_BOX.delete(0,tkinter.END)
  614. cookies_BOX.insert(0,*cookies)
  615. def startDownloader():
  616. def startLoader():
  617. global loader,Page_Parser
  618. loader.strat_urlGet(func_cookie=cookies_BOX_Update)
  619. Page_Parser.Element_interaction(update_Status)
  620. new = threading.Thread(target=startLoader)
  621. new.start()
  622. update_URLBOX()
  623. def add_filter_func_HTTPS():
  624. global url
  625. url.Add_func(lambda url:re.match(re.compile('^https://'),url),'HTTPS过滤')
  626. update_Func_BOX()
  627. def add_filter_func_WWW():
  628. global url
  629. url.Add_func(lambda url:re.match(re.compile('.*www\.'),url),'www过滤')
  630. update_Func_BOX()
  631. def del_func():
  632. global URL_BOX
  633. index = Func_BOX.curselection()[0]
  634. url.Del_func(index)
  635. update_Func_BOX()
  636. def update_Func_BOX():
  637. global url,Func_BOX
  638. Func_BOX.delete(0,tkinter.END)
  639. Func_BOX.insert(tkinter.END,*url.return_func())
  640. def del_url():
  641. global URL_BOX
  642. index = URL_BOX.curselection()[0]
  643. url.del_url(index)
  644. update_URLBOX()
  645. def add_args():
  646. global URL_ARGS, UA_Input, use_Cookies_Input,FUNC_Input,DATA_Input
  647. try:
  648. data = eval(DATA_Input.get(),{})
  649. except:
  650. data = {}
  651. re = dict(
  652. func = FUNC_Input.get(),
  653. UA = UA_Input.get(),
  654. cookies = use_Cookies_Input.get(),
  655. data=data
  656. )
  657. name = ['no_js','no_java','no_plugins','first_run','head','no_img','new']
  658. for i in range(len(name)):
  659. re[name[i]] = bool(URL_ARGS[i].get())
  660. return re
  661. def add_url():
  662. global URL_Input,url
  663. args = add_args()
  664. new_url = URL_Input.get()
  665. if new_url == '':return
  666. url.add_url(new_url,**args)
  667. update_URLBOX()
  668. def add_url_from_tag():
  669. global URLTAG_Input,Page_Parser,Var_Input
  670. try:
  671. index = eval(VarIndex_Input.get(),{})
  672. except:
  673. index = slice(None,None)
  674. Page_Parser.add_url(element_value=Var_Input.get(),index=index,url_name=URLTAG_Input.get(),update_func=update_URLBOX,
  675. url_args=add_args())
  676. Update_Parser_Func_BOX()
  677. def update_URLBOX():
  678. global url,URL_BOX
  679. URL_BOX.delete(0,tkinter.END)
  680. URL_BOX.insert(tkinter.END,*url.return_url())
  681. if __name__ == "__main__":
  682. Main()