├── .gitignore ├── LICENSE ├── README.md ├── chromedriver ├── chromedriver_80.exe ├── chromedriver_81.exe ├── chromedriver_83.exe ├── chromedriver_86.exe └── chromedriver_87.exe ├── config.ini ├── dist └── demo.exe └── scr ├── config.py ├── demo.py ├── exam.py └── log.py /.gitignore: -------------------------------------------------------------------------------- 1 | config.ini 2 | *.log 3 | log/ 4 | *.txt 5 | build/ 6 | *.spec 7 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 程序说明 2 | 3 | 程序目的主要还是练手自动化 ~~*顺便偷懒*,~~ 4 | 5 | ~~答案接口:https://uexercise.unipus.cn/itest/t/clsExam/rate/detail?%s%s%s' % (exercise, sign, sid) sid是登录之后页面pagesource里的studentid:~~ 6 | 7 | 8 | sid获取> 主页面里面,右键检查,在html里面ctrl+f搜索sid:,后面出现的数字就是了 9 | 不过还请手动配置 chromedriver 10 | 11 | 选择自己谷歌相应版本的chromedriver然后把exe文件移动到chromedriver文件夹下,**并改成相应格式的名字** 12 | 13 | 14 | 15 | **支持的 course:** 16 | 17 | *新四级强化辅导课程,新视野大学英语的单元测验部分* 18 | 19 | ~~*有时间的人其他课程可以试一试,万一也可用呢?(如果可用还请告诉我一声)*~~ 20 | 21 | **支持题型:** 22 | 23 | (暂不支持自动填写作文翻译😂,但是仍可用) 24 | 25 | * **纯填空**: 复合式听写|仔细阅读|长篇阅读 26 | * **选词填空**:词汇理解...~~(功能匮乏~~ 27 | * **选择题**:短对话,长对话,新闻报道 28 | 29 | **环境配置:** 30 | 31 | win10 x64 32 | 33 | ## 使用说明 34 | 35 | ### 配置文件 36 | 37 | * 第一次使用需要你配置config中你的用户名,密码~~(可以在config里直接改)~~之后是默认你第一次的配置 38 | 39 | 如果你想改配置: 40 | 41 | 可以在config.ini里面直接改 42 | 43 | 也可以在程序里按照提示输入相应指令 44 | 45 | ### 配置参数说明: 46 | 47 | * is_auto_submit=1 代表自动提交|不建议,所以默认为0 (待优化,还未能使用) 48 | * is_close_answerwindow=1 代表关闭出现的答案窗口|自行决定 49 | * username 登录账号 50 | * password 登录密码 51 | * studentId sid 52 | * auto_fill_answer=1 代表自动答题 默认1 53 | * v_chromedriver 谷歌版本号 54 | * wtmax 间隔最大时间 /second 默认0.3s 55 | * wtmin 间隔最小时间 /second 默认0.3s 56 | 57 | ### 自动答题 58 | 59 | **进入需要完成的test,确认开始后即可自动**,自动答题中**不要**切换窗口以防终止答题 60 | 61 | ## 一些常见issue: 62 | 63 | * 有验证码出现是无法答题的,请自行解决验证码问题 64 | 65 | * **自动填写并未填写完**:可到关闭测验再执行一遍,因为有时候答案数据未加载出来,具体可以在答案页面看见 66 | * **有黑方框但是程序登录页面打不开**:**检查本程序是否支持你的谷歌版本**,或者是账号密码错误 67 | * **答案页面显示不了答案**:务必检查一下sid是否正确 68 | * **如果黑方框闪退**:~~这个原因挺多~~ 先看一下是不是下载的压缩包,不要单独下载exe,也有可能是杀毒软件的锅,最可能的是账号密码错误或者chrome版本不匹配 69 | 70 | **(提交时若显示你有题未作答是因为U校园系统没有来得及保存,不用管直接提交就好了)** 71 | 72 | 最后记得退出程序 73 | 74 | 75 | 76 | ## 特别感谢 77 | 78 | * [ 85853444](https://github.com/858534444) 79 | 80 | * zhou1024 81 | 82 | **对本程序的支持,以及陪我耐心的调试** 83 | 84 | ## 本程序仅供学习交流 85 | 86 | 使用本程序一切后果,本人概不负责 87 | -------------------------------------------------------------------------------- /chromedriver/chromedriver_80.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/chromedriver/chromedriver_80.exe -------------------------------------------------------------------------------- /chromedriver/chromedriver_81.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/chromedriver/chromedriver_81.exe -------------------------------------------------------------------------------- /chromedriver/chromedriver_83.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/chromedriver/chromedriver_83.exe -------------------------------------------------------------------------------- /chromedriver/chromedriver_86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/chromedriver/chromedriver_86.exe -------------------------------------------------------------------------------- /chromedriver/chromedriver_87.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/chromedriver/chromedriver_87.exe -------------------------------------------------------------------------------- /config.ini: -------------------------------------------------------------------------------- 1 | [DATABASE] 2 | is_atuo_submit = 0 3 | is_close_answerwindow = 0 4 | username = 5 | password = 6 | studentid = 7 | auto_fill_answer = 1 8 | v_chromedriver = 9 | wtmax = 0.3 10 | wtmin = 0.3 11 | 12 | -------------------------------------------------------------------------------- /dist/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dummerchen/Ucampus/21190df007a71f8e9bb80caa7ff3c1728ee3b71d/dist/demo.exe -------------------------------------------------------------------------------- /scr/config.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : Dummerfu 3 | # @Time : 2020/5/20 8:52 4 | import configparser 5 | import os 6 | import re 7 | from selenium import webdriver 8 | from log import Loggers 9 | 10 | loggers=Loggers() 11 | cf = configparser.ConfigParser() 12 | path=os.path.abspath('..') 13 | cf.read(path+'/config.ini') 14 | def change_config(): 15 | opt=cf.options('DATABASE') 16 | 17 | for i,name in enumerate(opt): 18 | print(i,'---->\n','当前配置名称为%s\n'%name,'是',cf.get('DATABASE',name)) 19 | while 1: 20 | num=input('请输入要更改的配置文件序号|return退出') 21 | if num=='return': 22 | break 23 | new = input('输入新的该文件') 24 | try: 25 | cf.set('DATABASE',opt[int(num)],new) 26 | except: 27 | print('出错了!') 28 | break 29 | cf.write(open(path+'/config.ini','w')) 30 | def check_cd(): 31 | if cf.get('DATABASE','v_chromedriver')=='': 32 | file_name=os.listdir(path+'\\chromedriver') 33 | file_name=file_name[::-1] 34 | 35 | for name in file_name: 36 | try: 37 | pathcd=path+'\\chromedriver\\'+name 38 | # 如果有配置环境变量可以把这个改为 39 | #driver=webdriver.Chrome() 40 | print(pathcd) 41 | driver = webdriver.Chrome(pathcd) 42 | # print(name) 43 | # print(re.findall('\d+',name)) 44 | cf.set('DATABASE','v_chromedriver',re.findall('\d+',name)[0]) 45 | cf.write(open(path + '/config.ini', 'w')) 46 | return driver 47 | except Exception as e: 48 | loggers.logger.info(e) 49 | 50 | else: 51 | pathcd = path + '/chromedriver/chromedriver_%s.exe' %cf.get('DATABASE','v_chromedriver') 52 | # 这里也要改 53 | #driver = webdriver.Chrome() 54 | driver = webdriver.Chrome(pathcd) 55 | return driver 56 | print('请确认支持的版本或手动配置chrome相应的chromedriver版本到chromedriver文件夹') 57 | 58 | def get_sid(driver): 59 | driver.switch_to.window(driver.window_handles[0]) 60 | text=driver.page_source 61 | studentid = re.findall('sid:\d+',text)[0].replace('sid:','') 62 | cf.set('DATABASE','studentid',str(studentid)) 63 | cf.write(open(path + '/config.ini', 'w')) 64 | return studentid 65 | def get_config(): 66 | 67 | if cf.get('DATABASE','username')=='': 68 | username = input('缺失账号,请输入账号\n') 69 | cf.set('DATABASE','username',username) 70 | if cf.get('DATABASE','password')=='': 71 | password = input('缺失密码,请输入密码\n') 72 | cf.set('DATABASE','password',password) 73 | 74 | cf.write(open(path+'/config.ini', 'w')) 75 | l=[] 76 | for i in cf.options('DATABASE'): 77 | l.append(cf.get('DATABASE', i)) 78 | return l[:6] 79 | if __name__ == '__main__': 80 | l=get_config() 81 | print(l) 82 | check_cd() -------------------------------------------------------------------------------- /scr/demo.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : Dummerfu 3 | # @Time : 2020/5/19 18:25 4 | 5 | # v 3.1.1 6 | # some courses-> many units-> many tests 7 | import os 8 | import config 9 | import exam 10 | from log import Loggers 11 | import time 12 | 13 | loggers=Loggers() 14 | 15 | def login(): 16 | ''' 17 | 从config里面获取信息并登录 18 | :return: driver 19 | ''' 20 | url='https://sso.unipus.cn/sso/login?service=https%3A%2F%2Fu.unipus.cn%2Fuser%2Fcomm%2Flogin%3Fschool_id%3D' 21 | driver=config.check_cd() 22 | driver.get(url) 23 | 24 | driver.find_element_by_name('username').send_keys(test.username) 25 | driver.find_element_by_name('password').send_keys(test.password) 26 | driver.find_element_by_id('login').click() 27 | 28 | driver.implicitly_wait(3) 29 | try: 30 | driver.find_element_by_class_name('layui-layer-btn0').click() 31 | driver.switch_to.window(driver.window_handles[-1]) 32 | driver.close() 33 | except Exception as e: 34 | driver.switch_to.window(driver.window_handles[0]) 35 | print('如果出现验证码请手动登录后请重启程序,如果账号密码错误请更改config.ini文件') 36 | loggers.logger.exception(e) 37 | 38 | return driver 39 | 40 | test=exam.Test() 41 | 42 | def main(): 43 | 44 | print('如果有问题请先看readme') 45 | print('如果出现验证码检查是否账号密码错误,把窗口关闭并重新打开软件,直到没有验证码') 46 | print('获取答案后自动答题将会有7s左右的等待时间,不要退出!!!') 47 | print('如果还有问题 请将log文件夹下的最新文件+测试链接 反馈bug\n(自古readme没人看,只好写这了)') 48 | print('更改用户密码建议到config.ini') 49 | print('-' * 40) 50 | flag=input('是否要更改配置文件(config.ini) y|n (回车默认不更改') 51 | 52 | if flag=='y': 53 | config.change_config() 54 | else: 55 | pass 56 | test.is_auto_submit,test.is_close_answerwindow,test.username,test.password,test.studentid,test.auto_fill_answer=config.get_config() 57 | 58 | 59 | driver = login() 60 | test.driver = driver 61 | if test.studentid=='': 62 | try: 63 | while 1: 64 | 65 | test.studentid=config.get_sid(driver) 66 | if test.studentid: 67 | loggers.logger.info(test.studentid) 68 | break 69 | else: 70 | print('如果一直在获取可以退出并重启程序') 71 | except Exception as e: 72 | loggers.logger.exception(e) 73 | print('未找到形如sid:XXX,请手动配置或者因u版本已更新本软件已经不支持,欢迎反馈') 74 | time.sleep(4) 75 | return 76 | 77 | while 1: 78 | 79 | os.system('cls') 80 | flag=input('进入可答题页面后,任意输入来确认开始') 81 | os.system('cls') 82 | print('答题完成后建议人工检查一下,如有未完成的题建议刷新再尝试一次不要提交因为答案乱序了!(软件不太稳定,第二次基本能全部答完)') 83 | print('答题开始,请勿退出或滑动页面') 84 | try: 85 | test.get_answer() 86 | if test.auto_fill_answer=='1': 87 | print('正在准备自动答题') 88 | test.solve() 89 | print('答题完成,请提交') 90 | time.sleep(3) 91 | else: 92 | print('已选择手动答题,请手动答题时不要关闭程序') 93 | except Exception as e: 94 | loggers.logger.exception(e) 95 | print('出错了,如果自动答题未答全可以刷新再来一次或手动答题(软件不太稳定\n') 96 | time.sleep(4) 97 | 98 | if __name__=='__main__': 99 | os.system('cls') 100 | main() -------------------------------------------------------------------------------- /scr/exam.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : Dummerfu 3 | # @Time : 2020/5/22 19:33 4 | import re 5 | import time 6 | import random 7 | from bs4 import BeautifulSoup 8 | from selenium.webdriver.support.wait import WebDriverWait 9 | from selenium.webdriver.support import expected_conditions as ec 10 | from selenium.webdriver.common.by import By 11 | import config 12 | from log import Loggers 13 | 14 | # 存储所有label=green的值 ,包括选择题会出现两个一样的 15 | anslist=[] 16 | loggers=Loggers() 17 | # 题号 18 | def wait(): 19 | minn=float(config.cf.get('DATABASE','wtmin')) 20 | maxn=float(config.cf.get('DATABASE','wtmax')) 21 | time.sleep(random.uniform(minn,maxn)) 22 | class Test(object): 23 | def __init__(self): 24 | self.username='' 25 | self.password='' 26 | self.studentid='' 27 | self.target_url='' 28 | self.driver=None 29 | # 新视野是sign+exerciseid+studentid 30 | # 但是四六级不需要sid也可以 31 | # studentid在个人中心页面 32 | self.testlist=[] 33 | self.auto_fill_answer=None 34 | self.is_close_answerwindow=None 35 | self.is_auto_submit=None 36 | def start_exam(self): 37 | self.driver.get(self.target_url) 38 | # 这里必须是timesleep? 因为他本来就有但是没有弹出来 39 | try: 40 | # 第一种登录方法 正常情况 41 | time.sleep(3) 42 | self.driver.find_element_by_xpath('/html/body/div[6]/div/div[1]/div/div/div[1]/i').click() 43 | 44 | self.driver.implicitly_wait(10) 45 | self.driver.find_element_by_xpath('//*[@id="pageLayout"]/div/div[2]/div/div/div/button').click() 46 | except: 47 | # 第二种登录方法 非正常情况 48 | # 没有点击确认按钮,直接就进入了考试 49 | pass 50 | return 51 | def get_answer(self): 52 | 53 | anslist.clear() 54 | 55 | self.driver.switch_to.window(self.driver.window_handles[0]) 56 | ele=WebDriverWait(self.driver,1000).until(ec.presence_of_element_located((By.TAG_NAME,'iframe'))) 57 | url=ele.get_attribute('src') 58 | exercise = 'exerciseId=\d+&' 59 | sign = r'sign=\d*\w*&' 60 | exercise = re.findall(exercise, url)[0] 61 | sign = re.findall(sign, url)[0] 62 | sid = 'studentId='+self.studentid 63 | url = 'https://uexercise.unipus.cn/itest/t/clsExam/rate/detail?%s%s%s' % (exercise, sign, sid) 64 | 65 | js = 'window.open("https://baidu.com");' 66 | self.driver.execute_script(js) 67 | print('正在获取答案页面,请等待') 68 | self.driver.switch_to.window(self.driver.window_handles[-1]) 69 | try: 70 | self.driver.get(url) 71 | #怎么弄有时候都会加载不全...佛了 72 | time.sleep(3) 73 | self.driver.implicitly_wait(5) 74 | except Exception as e: 75 | loggers.logger.exception(e) 76 | html = self.driver.page_source 77 | temp = self.driver.find_elements_by_class_name('green') 78 | for i in temp: 79 | # 选择题读入和选词填空题读入都是一句话,其余的是一个单词|短语 80 | anslist.append((i.text).replace('(', '').replace(')', '').strip()) 81 | # 判断是否关闭答案窗口 82 | if self.is_close_answerwindow=='1': 83 | self.driver.close() 84 | 85 | soup=BeautifulSoup(html,'lxml') 86 | self.testlist=soup.find_all(name='div',attrs={'class','Test'}) 87 | 88 | print('成功获取答案') 89 | loggers.logger.info('获取答案成功') 90 | 91 | return 0 92 | def solve(self): 93 | 94 | self.driver.switch_to.window(self.driver.window_handles[0]) 95 | try: 96 | self.driver.switch_to.frame('iframe') 97 | except: 98 | pass 99 | 100 | # 有的还有个加载成功弹窗 101 | try: 102 | self.driver.implicitly_wait(10) 103 | self.driver.find_element_by_id('success-ok').click() 104 | except: 105 | pass 106 | 107 | # 得到所有题目的种类 108 | itest_section = self.driver.find_elements_by_class_name('itest-section') 109 | 110 | # 答案的位置,输入框的位置 111 | ansnum=-1 112 | for i,section in enumerate(itest_section): 113 | text=section.get_attribute('part1') 114 | #print(text) 115 | flag = check(text) 116 | if flag == 1: 117 | ansnum=self.multiple_choices(i,section,ansnum) 118 | elif flag == 2: 119 | ansnum=self.multiple_selection(i,section,ansnum) 120 | elif flag == 3: 121 | ansnum=self.chun_tiankong(i,section,ansnum) 122 | elif flag ==4: 123 | ansnum=self.xuanci_tiankong(i,section,ansnum) 124 | self.submint() 125 | def chun_tiankong(self,th,section,ansnum): 126 | ''' 127 | 纯填空题 128 | :param section:第几部分 129 | :param ansnum: 到第几个答案 130 | :return: ansnum 131 | ''' 132 | # 这个部分下所有的大题 133 | question_set=section.find_elements_by_class_name('itest-ques-set') 134 | for i,wordlist in enumerate(question_set): 135 | # 得到每个大题需要填的空 136 | need_input_list=(question_set[i]).find_elements_by_tag_name('input') 137 | for j in range(0,len(need_input_list)): 138 | wait() 139 | ansnum+=1 140 | self.driver.execute_script("arguments[0].value=arguments[1]", need_input_list[j],anslist[ansnum]) 141 | return ansnum 142 | def xuanci_tiankong(self,th,section,ansnum): 143 | ''' 144 | 选词填空题 145 | :param section:第几部分 146 | :param ansnum: 到第几个答案 147 | :return: ansnum 148 | ''' 149 | 150 | # 因为wordlist这是在答案页面存的所以有个th来找这是第几个section里面的,然后再找wordlist...其他的th没用懒得删了 151 | # 虽然感觉可以写简单 152 | wordlist_tot=self.testlist[th].select("div [class='Question-Conversation'] ul") 153 | # 这个部分下所有的大题 154 | question_set=section.find_elements_by_class_name('itest-ques-set') 155 | dic={} 156 | for i,wordlist in enumerate(wordlist_tot): 157 | # 找对应关系 158 | al=wordlist.find_all(name='li') 159 | for word in al: 160 | dic[word.text[4:]]=word.text[0] 161 | 162 | # 得到每个大题需要填的空 163 | need_input_list=(question_set[i]).find_elements_by_tag_name('input') 164 | for j in range(0,len(need_input_list)): 165 | wait() 166 | ansnum+=1 167 | self.driver.execute_script("arguments[0].value=arguments[1]", need_input_list[j],dic[anslist[ansnum]]) 168 | return ansnum 169 | def multiple_choices(self,th,section,ansnum): 170 | ''' 171 | 单选题 172 | :param section: 173 | :return:ansnum 174 | ''' 175 | global jishuqi 176 | 177 | question_set = section.find_elements_by_class_name('itest-ques-set') 178 | for i, wordlist in enumerate(question_set): 179 | # 得到每个大题需要填的空|选择题的空是一般题的四倍 180 | 181 | need_input_list = (question_set[i]).find_elements_by_tag_name('input') 182 | l=len(need_input_list) 183 | for j in range(0, int(l/4)): 184 | wait() 185 | ansnum += 2 186 | qoo=need_input_list[j*4].get_attribute('qoo').replace('[','').replace(']','').replace(',','') 187 | # qoo是随机打乱序列 qoo[原pos]=现pos 现在先用循环写着,以后再优化 188 | for step,k in enumerate(qoo): 189 | if eval(k)==(ord(anslist[ansnum][0])-ord('A')): 190 | (need_input_list[j*4+step]).click() 191 | break 192 | return ansnum 193 | def multiple_selection(self,th,section,ansnum): 194 | ''' 195 | 多选题 196 | :param section: 197 | :return: 198 | ''' 199 | return ansnum 200 | def submint(self,): 201 | # 前面已经进入了iframe里面就不需要再进了 202 | # 不同course button不同,以后再改吧 203 | if self.is_auto_submit=='1': 204 | self. driver.find_element_by_xpath('//*[@id="submit-answer"]').click() 205 | # self.driver.quit() 206 | print('答题完成,请提交') 207 | def check(text): 208 | ''' 209 | 判断这个部分的类型 单选|多选|填空 210 | :param text: 211 | :return: 212 | ''' 213 | danxuan=['短对话','仔细阅读','长对话','短文理解','新闻报道'] 214 | duoxuan=[''] 215 | chun_tiankong=['听写填空','复合式听写','长篇阅读'] 216 | xuanci_tiankong=['词汇理解'] 217 | if text in danxuan: 218 | return 1 219 | elif text in duoxuan: 220 | return 2 221 | elif text in chun_tiankong: 222 | return 3 223 | elif text in xuanci_tiankong: 224 | return 4 -------------------------------------------------------------------------------- /scr/log.py: -------------------------------------------------------------------------------- 1 | #-*- coding:utf-8 -*- 2 | # @Author : Dummerfu 3 | # @Time : 2020/10/29 18:54 4 | ''' 5 | 生成日志文件 6 | ''' 7 | import logging 8 | from logging import handlers 9 | import os 10 | import time 11 | class Loggers(object): 12 | def __init__(self,encoding=None,level=logging.INFO): 13 | path=os.path.abspath('..') 14 | path=os.path.join(path,'log') 15 | self.encoding=encoding 16 | self.level=level 17 | 18 | if not os.path.exists(path): 19 | os.mkdir(path) 20 | 21 | 22 | __time__ = time.strftime('%Y_%m_%d_%H_%M',time.localtime(time.time())) 23 | 24 | self.logger = logging.getLogger('log') 25 | 26 | self.logger_name=os.path.join(path,'default') 27 | 28 | # 防止不正确调用 造成handle重复 29 | while self.logger.hasHandlers(): 30 | for i in self.logger.handlers: 31 | self.logger.removeHandler(i) 32 | 33 | self.logger.setLevel(self.level) 34 | 35 | fh=logging.handlers.TimedRotatingFileHandler(filename=self.logger_name,when="S",interval=1,backupCount=50,encoding='utf-8') 36 | 37 | formater = logging.Formatter('%(asctime)s [%(filename)s] (%(levelname)s) : %(message)s') 38 | fh.setFormatter(formater) 39 | 40 | self.logger.addHandler(fh) 41 | 42 | # 初始信息 43 | # self.logger.info(path) 44 | 45 | 46 | if __name__ == '__main__': 47 | logger=Loggers() 48 | # try: 49 | # while 1: 50 | # print(aaa) 51 | # except Exception as e: 52 | # logger.logger.exception(e) --------------------------------------------------------------------------------