Skip to content

Commit e877c44

Browse files
committed
1.2
1 parent 097a345 commit e877c44

File tree

7 files changed

+72
-28
lines changed

7 files changed

+72
-28
lines changed

main/chrome.py login/chrome.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@time: 2019/4/14 23:10
88
@desc:
99
"""
10+
from main.login import login
1011
from selenium import webdriver
1112

1213
import config
13-
from main.login import login
1414

1515

1616
def main():

main/login.py login/login.py

File renamed without changes.

mail.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from email.mime.text import MIMEText
77
from email.utils import formataddr
88

9-
from config import host, mail_username as username, mail_password as password
9+
from config import mail_host as host, mail_username as username, mail_password as password
1010

1111

1212
def loginToServer(host, user, password):

main.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: SSSimon Yang
5+
6+
@file: login.py
7+
@time: 2019/11/27 17:01
8+
@desc: curate function
9+
"""
10+
11+
import argparse
12+
13+
import config
14+
from personal_page.evaluation import process
15+
16+
if __name__ == '__main__':
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("-id", "--id", help="specify your user id")
19+
parser.add_argument("-pw", "--password", help="specify your user password")
20+
args = parser.parse_args()
21+
if args.id and args.password:
22+
process(args.id, args.password)
23+
else:
24+
process(config.user_id, config.user_password)

personal_page/evaluation.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
from urllib import parse
1616

1717
from lxml import etree
18-
from urllib3 import HTTPSConnectionPool
1918

20-
import config
19+
from login.login import login
2120
from mail import send_mail
22-
from main.login import login
2321

2422

2523
def access(s):
@@ -121,7 +119,7 @@ def process(user_id, user_password, email=''):
121119
"""
122120
try:
123121
s = login(user_id, user_password)
124-
except HTTPSConnectionPool:
122+
except ConnectionError:
125123
print(f"{user_id} Error")
126124
return f"{user_id} failed"
127125
except Exception as e:
@@ -137,6 +135,7 @@ def process(user_id, user_password, email=''):
137135

138136

139137
if __name__ == '__main__':
140-
# main(r'************.csv')
141-
process(config.user_id, config.user_password)
138+
pass
139+
# login(r'************.csv')
140+
# process(config.user_id, config.user_password)
142141
# process(config.user_id, config.user_password, config.user_email)

personal_page/tuimian.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import xml.etree.ElementTree as ET
1515

1616
from lxml import etree
17+
from main.login import login
1718
from openpyxl import Workbook
1819

1920
from config import user_id, user_password
20-
from main.login import login
2121

2222

2323
def main(grade="2016"):

readme.md

+40-19
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,38 @@
22

33
> 所有代码主要爬虫对象为西南交通大学教务网或扬华网
44
5-
- /homepage/jiaowu.py 教务网主页信息爬取
6-
- /homepage/yanghua.py 扬华网信息爬取
7-
- /main/chrome.py chrome模拟登录教务网
8-
- /main/login.py 利用百度api识别验证码登录教务网
9-
- /personal_page/evaluation.py 教务登陆后个人主页完成课程评价
10-
- /personal_page/tuimian.py 教务登陆后个人主页完成保研课查询
11-
- /mail.py 辅助完成邮件发送
5+
- `/homepage/jiaowu.py` 教务网主页信息爬取
6+
- `/homepage/yanghua.py` 扬华网信息爬取
7+
- `/login/chrome.py` chrome模拟登录教务网
8+
- `/login/login.py` 利用百度api识别验证码登录教务网
9+
- `/personal_page/evaluation.py` 教务登陆后个人主页完成课程评价
10+
- `/personal_page/tuimian.py` 教务登陆后个人主页完成保研课查询
11+
- `/mail.py` 辅助完成邮件发送
12+
- `/main.py` 运行程序
1213

1314
涉及到的库
14-
baidu-aip lxml openpyxl Pillow psycopg2 requests selenium xlrd
15+
`baidu-aip lxml openpyxl Pillow psycopg2 requests selenium xlrd`
1516

1617
> python版本 最低为3.6
1718
1819
安装包
1920
`pip install baidu-aip lxml openpyxl Pillow requests xlrd`
20-
> 除baidu-aip之外的所有包都可用conda安装
21+
> `baidu-aip`之外的所有包都可用`conda`安装
2122
2223
### 自动评价
2324
自动评价涉及的文件为
24-
- /main/login.py
25-
- /personal_page/evaluation.py
25+
- `/login/login.py`
26+
- `/personal_page/evaluation.py`
27+
- `/config.py` 需自行创建
28+
- `/main.py`
2629

2730
进入[百度ai开放平台](http://ai.baidu.com/)
2831
点击控制台 登录 选择左侧文字识别 然后创建应用
2932
应用的名字和简介随便写,常见成功后会显示`AppID API Key Secret Key`
3033
在该目录下创建`config.py`
3134

3235
-----------
33-
config.py
36+
`config.py`
3437
```
3538
APP_ID = '17868961' # 对应替换为你申请的AppID
3639
API_KEY = 'sZGw4ynaOLIdXoijfI5IFbYX' # 对应替换为你申请的API Key
@@ -42,27 +45,45 @@ user_password = '*****' # 对应写入你自己的教务密码
4245
4346
该目录下运行
4447
`
45-
python personal_page/evaluation.py
48+
python main.py
49+
`
50+
或运行时指定
51+
`
52+
python main.py -id <your_user_id> -pw <your_user_password>'
4653
`
4754

48-
#### 启动`mail.py`的功能
55+
#### 启用`mail.py`的功能
4956
`config.py`加入如下信息
5057
```
5158
mail_username = '****************' # email地址
5259
mail_password = '****************' # email开启smtp服务后提供的登录授权码
5360
host = 'smtp.***.com' # 对应的smtp服务器
5461
user_email = '****************' # 通知到的email地址
5562
```
56-
然后更改evaluation.py的最后部分
63+
然后更改`main.py`的部分
5764
```
5865
if __name__ == '__main__':
59-
# main(r'************.csv')
60-
# process(config.user_id, config.user_password)
61-
process(config.user_id, config.user_password, config.user_email)
66+
parser = argparse.ArgumentParser()
67+
parser.add_argument("-id", "--id", help="specify your user id")
68+
parser.add_argument("-pw", "--password", help="specify your user password")
69+
parser.add_argument("-email", "--email", help="specify your email address to send to")
70+
args = parser.parse_args()
71+
if args.id and args.password:
72+
process(args.id, args.password, args.email)
73+
else:
74+
process(config.user_id, config.user_password, config.user_email)
6275
```
6376
同样,执行
6477
`
65-
python personal_page/evaluation.py
78+
python main.py
79+
`
80+
6681
`
82+
python main.py -id <your_user_id> -pw <your_user_password>'
83+
`
84+
85+
### 批量化
86+
编辑csv文件
87+
`/personal_page/evaluation.py`中的`main.py`进行相应更改
6788

6889
Wish you a good day!

0 commit comments

Comments
 (0)