5
5
"""
6
6
7
7
__author__ = "yanyongyu"
8
- __all__ = ["cxmooc_tool" , "poxiaobbs" , "forestpolice" , "bankroft " ,
9
- "jiuaidaikan " , "wangke120 " ]
8
+ __all__ = ["cxmooc_tool" , "poxiaobbs" , "forestpolice" , "jiuaidaikan " ,
9
+ "wangke120 " , "xuanxiu365 " ]
10
10
11
11
import sys
12
12
import json
13
13
import logging
14
14
import asyncio
15
- from hashlib import md5
15
+ # from hashlib import md5
16
16
17
17
import requests
18
18
from lxml import etree
@@ -179,74 +179,74 @@ async def forestpolice(sess: requests.Session,
179
179
raise StopIteration
180
180
181
181
182
- async def bankroft (sess : requests .Session ,
183
- * args : list ) -> list :
184
- """
185
- 该接口只有当题目完整时可用!
186
- 并且有频率限制!
187
- """
188
- # 输入参数处理
189
- if not isinstance (sess , requests .Session ):
190
- args = list (args )
191
- args .insert (0 , sess )
192
- args = tuple (args )
193
- sess = requests .Session ()
194
-
195
- # 接口
196
- string_enc = "-b?M#JvMg2y3$JMk"
197
- url = "http://123.207.19.72/api/query?"
198
-
199
- # 接口参数
200
- index = yield
201
- payload = {}
202
- for i in range (len (args )):
203
- if index and i < index :
204
- continue
205
- md = md5 ()
206
- md .update ((args [i ]+ string_enc ).encode ())
207
-
208
- payload ['title' ] = args [i ]
209
- payload ['enc' ] = md .hexdigest ()
210
-
211
- # post请求
212
- logging .info ("Get bankroft api. Question %d" % i )
213
- try :
214
- res = sess .get (url , params = payload , verify = False , timeout = 5 )
215
- res .raise_for_status ()
216
- except requests .exceptions .RequestException as e :
217
- logging .info ("Request Exception appeared: %s" % e )
218
- answer = []
219
- answer .append ({'topic' : str (e ),
220
- 'correct' : '' })
221
- index = yield answer
222
- continue
223
-
224
- # 处理结果
225
- logging .info ("Processing result" )
226
- answer = []
227
- json_text = res .json ()
228
- if json_text ['code' ] == 100 :
229
- temp = {}
230
- temp ['topic' ] = args [i ]
231
- temp ['correct' ] = json_text ['data' ]
232
- answer .append (temp )
233
- elif json_text ['code' ] == 101 :
234
- temp = {}
235
- temp ['topic' ] = "题目输入不完整!bankroft接口需要除题目类型外完整题目"
236
- temp ['correct' ] = ""
237
- answer .append (temp )
238
- else :
239
- temp = {}
240
- temp ['topic' ] = "bankroft接口查询次数已达上限!"
241
- temp ['correct' ] = ""
242
- answer .append (temp )
243
-
244
- logging .info ("Yield question %s: %s" % (i + 1 , answer ))
245
- index = yield answer
246
-
247
- await asyncio .sleep (0.5 )
248
-
249
- raise StopIteration
182
+ # async def bankroft(sess: requests.Session,
183
+ # *args: list) -> list:
184
+ # """
185
+ # 该接口只有当题目完整时可用!
186
+ # 并且有频率限制!
187
+ # """
188
+ # # 输入参数处理
189
+ # if not isinstance(sess, requests.Session):
190
+ # args = list(args)
191
+ # args.insert(0, sess)
192
+ # args = tuple(args)
193
+ # sess = requests.Session()
194
+ #
195
+ # # 接口
196
+ # string_enc = "-b?M#JvMg2y3$JMk"
197
+ # url = "http://123.207.19.72/api/query?"
198
+ #
199
+ # # 接口参数
200
+ # index = yield
201
+ # payload = {}
202
+ # for i in range(len(args)):
203
+ # if index and i < index:
204
+ # continue
205
+ # md = md5()
206
+ # md.update((args[i]+string_enc).encode())
207
+ #
208
+ # payload['title'] = args[i]
209
+ # payload['enc'] = md.hexdigest()
210
+ #
211
+ # # post请求
212
+ # logging.info("Get bankroft api. Question %d" % i)
213
+ # try:
214
+ # res = sess.get(url, params=payload, verify=False, timeout=5)
215
+ # res.raise_for_status()
216
+ # except requests.exceptions.RequestException as e:
217
+ # logging.info("Request Exception appeared: %s" % e)
218
+ # answer = []
219
+ # answer.append({'topic': str(e),
220
+ # 'correct': ''})
221
+ # index = yield answer
222
+ # continue
223
+ #
224
+ # # 处理结果
225
+ # logging.info("Processing result")
226
+ # answer = []
227
+ # json_text = res.json()
228
+ # if json_text['code'] == 100:
229
+ # temp = {}
230
+ # temp['topic'] = args[i]
231
+ # temp['correct'] = json_text['data']
232
+ # answer.append(temp)
233
+ # elif json_text['code'] == 101:
234
+ # temp = {}
235
+ # temp['topic'] = "题目输入不完整!bankroft接口需要除题目类型外完整题目"
236
+ # temp['correct'] = ""
237
+ # answer.append(temp)
238
+ # else:
239
+ # temp = {}
240
+ # temp['topic'] = "bankroft接口查询次数已达上限!"
241
+ # temp['correct'] = ""
242
+ # answer.append(temp)
243
+ #
244
+ # logging.info("Yield question %s: %s" % (i+1, answer))
245
+ # index = yield answer
246
+ #
247
+ # await asyncio.sleep(0.5)
248
+ #
249
+ # raise StopIteration
250
250
251
251
252
252
async def jiuaidaikan (sess : requests .Session ,
@@ -273,8 +273,6 @@ async def jiuaidaikan(sess: requests.Session,
273
273
res .raise_for_status ()
274
274
selector = etree .HTML (res .text )
275
275
viewstate = selector .xpath ('//*[@id="__VIEWSTATE"]/@value' )
276
- viewstategenerator = selector .xpath (
277
- '//*[@id="__VIEWSTATEGENERATOR"]/@value' )
278
276
eventvalidation = selector .xpath (
279
277
'//*[@id="__EVENTVALIDATION"]/@value' )
280
278
except requests .exceptions .RequestException as e :
@@ -291,7 +289,6 @@ async def jiuaidaikan(sess: requests.Session,
291
289
292
290
data = {}
293
291
data ['__VIEWSTATE' ] = viewstate
294
- data ['__VIEWSTATEGENERATOR' ] = viewstategenerator
295
292
data ['__EVENTVALIDATION' ] = eventvalidation
296
293
data ['ctl00$ContentPlaceHolder1$gen' ] = '查询'
297
294
for i in range (len (args )):
@@ -379,8 +376,61 @@ async def wangke120(sess: requests.Session,
379
376
raise StopIteration
380
377
381
378
382
- async def fm210 (sess : requests .Session ,
383
- * args : list ) -> list :
379
+ #async def fm210(sess: requests.Session,
380
+ # *args: list) -> list:
381
+ # # 输入参数处理
382
+ # if not isinstance(sess, requests.Session):
383
+ # args = list(args)
384
+ # args.insert(0, sess)
385
+ # args = tuple(args)
386
+ # sess = requests.Session()
387
+ #
388
+ # # 接口
389
+ # url = "http://api.fm210.cn/wangke/cx.php?"
390
+ #
391
+ # # 接口参数
392
+ # index = yield
393
+ # payload = {}
394
+ # for i in range(len(args)):
395
+ # if index and i < index:
396
+ # continue
397
+ # payload['w'] = args[i]
398
+ #
399
+ # # post请求
400
+ # logging.info("Post to fm120. Question %d" % i)
401
+ # try:
402
+ # res = sess.get(url, params=payload, verify=False, timeout=5)
403
+ # res.raise_for_status()
404
+ # except requests.exceptions.RequestException as e:
405
+ # logging.info("Request Exception appeared: %s" % e)
406
+ # answer = []
407
+ # answer.append({'topic': str(e),
408
+ # 'correct': ''})
409
+ # index = yield answer
410
+ # continue
411
+ #
412
+ # # 处理结果
413
+ # logging.info("Processing result")
414
+ # answer = []
415
+ # temp = {}
416
+ # try:
417
+ # temp['topic'] = res.text.split('\n')[1]
418
+ # temp['correct'] = res.text.split('\n')[3]
419
+ # if temp['correct'] != '':
420
+ # answer.append(temp)
421
+ # except IndexError:
422
+ # pass
423
+ #
424
+ # logging.info("Yield question %s: %s" % (i+1, answer))
425
+ # index = yield answer
426
+ #
427
+ # await asyncio.sleep(0.5)
428
+ #
429
+ # raise StopIteration
430
+
431
+
432
+ async def xuanxiu365 (sess : requests .Session ,
433
+ * args : list ) -> list :
384
434
# 输入参数处理
385
435
if not isinstance (sess , requests .Session ):
386
436
args = list (args )
@@ -389,20 +439,23 @@ async def fm210(sess: requests.Session,
389
439
sess = requests .Session ()
390
440
391
441
# 接口
392
- url = "http://api.fm210.cn/wangke/cx.php?"
442
+ url = "http://tiku.xuanxiu365.com/admin/admin/api.html"
443
+ header = {}
444
+ header ['X-Requested-With' ] = "XMLHttpRequest"
393
445
394
446
# 接口参数
395
447
index = yield
396
448
payload = {}
397
449
for i in range (len (args )):
398
450
if index and i < index :
399
451
continue
400
- payload ['w ' ] = args [i ]
452
+ payload ['search ' ] = args [i ]
401
453
402
454
# post请求
403
- logging .info ("Post to fm120 . Question %d" % i )
455
+ logging .info ("Post to xuanxiu365 . Question %d" % i )
404
456
try :
405
- res = sess .get (url , params = payload , verify = False , timeout = 5 )
457
+ res = sess .get (url , params = payload , headers = header ,
458
+ verify = False , timeout = 5 )
406
459
res .raise_for_status ()
407
460
except requests .exceptions .RequestException as e :
408
461
logging .info ("Request Exception appeared: %s" % e )
@@ -414,16 +467,13 @@ async def fm210(sess: requests.Session,
414
467
415
468
# 处理结果
416
469
logging .info ("Processing result" )
470
+ res = res .json ()
417
471
answer = []
418
- temp = {}
419
- try :
420
- temp ['topic' ] = res .text .split ('\n ' )[1 ]
421
- temp ['correct' ] = res .text .split ('\n ' )[3 ]
422
- if temp ['correct' ] != '' :
423
- answer .append (temp )
424
- except IndexError :
425
- pass
426
-
472
+ if res ['data' ]:
473
+ temp = {}
474
+ temp ['topic' ] = res ['data' ]['title' ]
475
+ temp ['correct' ] = res ['data' ]['content' ]
476
+ answer .append (temp )
427
477
logging .info ("Yield question %s: %s" % (i + 1 , answer ))
428
478
index = yield answer
429
479
@@ -432,6 +482,59 @@ async def fm210(sess: requests.Session,
432
482
raise StopIteration
433
483
434
484
485
+ #async def www150s(sess: requests.Session,
486
+ # *args: list) -> list:
487
+ # # 输入参数处理
488
+ # if not isinstance(sess, requests.Session):
489
+ # args = list(args)
490
+ # args.insert(0, sess)
491
+ # args = tuple(args)
492
+ # sess = requests.Session()
493
+ #
494
+ # # 接口
495
+ # url = "http://www.150s.cn/SearchServlet"
496
+ # header = {}
497
+ # header['X-Requested-With'] = "XMLHttpRequest"
498
+ #
499
+ # # 接口参数
500
+ # index = yield
501
+ # payload = {}
502
+ # for i in range(len(args)):
503
+ # if index and i < index:
504
+ # continue
505
+ # payload['text'] = args[i]
506
+ #
507
+ # # post请求
508
+ # logging.info("Post to www150s. Question %d" % i)
509
+ # try:
510
+ # res = sess.get(url, params=payload, headers=header,
511
+ # verify=False, timeout=5)
512
+ # res.raise_for_status()
513
+ # except requests.exceptions.RequestException as e:
514
+ # logging.info("Request Exception appeared: %s" % e)
515
+ # answer = []
516
+ # answer.append({'topic': str(e),
517
+ # 'correct': ''})
518
+ # index = yield answer
519
+ # continue
520
+ #
521
+ # # 处理结果
522
+ # logging.info("Processing result")
523
+ # res = res.json()
524
+ # answer = []
525
+ # temp = {}
526
+ # temp['topic'] = res['title']
527
+ # temp['correct'] = res['answer']
528
+ # if temp['topic'] != "查无此题,请您换一道题查询!":
529
+ # answer.append(temp)
530
+ # logging.info("Yield question %s: %s" % (i+1, answer))
531
+ # index = yield answer
532
+ #
533
+ # await asyncio.sleep(0.5)
534
+ #
535
+ # raise StopIteration
536
+
537
+
435
538
async def cmd ():
436
539
# 获取所有api
437
540
api_list = {}
0 commit comments