爬取毛概题库

 1 '''
 2 @name:  spider
 3 @data:  2016-6-16 22:56
 4 @author:  wangqj
 5 @blog:  http://www.cnblogs.com/a1225234/
 6 @e-mail:  1327563882@163.com
 7 '''
 8 import urllib
 9 import re
10 from bs4 import BeautifulSoup
11 
12 fil=open('01.txt','r')
13 soup = BeautifulSoup(fil.read(),'html.parser')
14 _list=soup.find(attrs={'name':'tryForm'})
15 _list_tr=_list.find_all('input')
16 pan_list=[]
17 num=1
18 k=1
19 n=61#tihao
20 print '判断题'
21 for i in _list_tr[0:50]:
22     if(num%5==3):
23         print n,'.',i['value'],
24         n+=1
25     if(num%5==4):
26         if(int(i['value'])==1):
27             print '正确'
28         else:
29             print '错误'
30     num+=1
31 num=1
32 k=50
33 n=n-10#tihao
34 print '单选题'
35 for i in _list_tr[50:160]:
36     t=num%11       
37     if(t==9):
38         print n,'.',
39         n+=1
40         print i['value'],'(',_list_tr[k+1]['value'],')'
41         print 'A.',_list_tr[k-4]['value'],'\nB.',_list_tr[k-3]['value']
42         print 'C.',_list_tr[k-2]['value'],'\nD.',_list_tr[k-1]['value']
43     k+=1
44     num+=1
45 print '多选题'
46 num=1
47 k=160
48 n=n-10#tihao
49 for i in _list_tr[160:270]:
50     t=num%11       
51     if(t==9):
52         print n,'.',
53         n+=1
54         print _list_tr[k]['value'],_list_tr[k+1]['value']
55         print 'A.',_list_tr[k-4]['value'],'\nB.',_list_tr[k-3]['value']
56         print 'C.',_list_tr[k-2]['value'],'\nD.',_list_tr[k-1]['value']
57     k+=1
58     num+=1

 

posted @ 2016-06-19 23:15  御心飞行  阅读(528)  评论(0编辑  收藏  举报