According to the list of students (excel file) statistics on the QQ group members (assistants might need)


Brief Description:
List a classroom of students existing excel file, statistics on the QQ group members from a list of students on the list to find the [students] and [the students] are not on the list.


Ideas:
the pages of a copy of some elements out, be xml analysis.


Requirements:
1, the first Excel file as a C student name.
2, QQ group owner's name formats are: [Name - the name of the class] or [] or [empty].


Specific steps:

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Input.html new file, the upper frame to copy the code input.html file.
Here Insert Picture Description
Run the program test.py analysis, as follows:

######################################################################
#
# 使用方法:
# 1、人工确保所有名字格式严格正确(“姓名”或者“姓名-班级”)。
# 2、将qq群成员管理网页html中的table元素copy到input.html中。
# 3、运行程序。
# 
######################################################################

from lxml import etree
import xlrd

lines = open('input.html', encoding='utf-8').readlines()

html=''
for line in lines:
    html += line;

page = etree.HTML(html)
members = page.findall('.//table[@id="groupMember"]/tbody[@class="list"]/tr')

count = 0
insiders_num = 0
outsiders_mum = 0
data=xlrd.open_workbook(r'计算机xx选课名单.xls')
sheet1 = data.sheets()[0]
outsiders = [] # 存放不在名单中的人

for member in members:
    name = member.findall('.//td[@class="td-card"]/span/span')
    if name[0].text == None: # 如果群名称为空
        name = ""
    else:
        name = name[0].text.strip().split('-')[0]
    qq = member.findall('.//td')[4]
    qq = qq.text.strip()
    
    print (str(count+1)+':', end=' ')
    print (name,end=' ')

    # 搜索name是否在excel名单中
    flag = False
    if (len(name) >= 2 and len(name) <= 3):
        rows = sheet1.nrows
        for i in range(rows):
            excel_mem_nam = str(sheet1.cell(i,2).value)
            if (excel_mem_nam.find(name) != -1):
                flag = True
                break

    if (flag): # 如果在excel名单中
        insiders_num += 1
        print ('yes')
    else: # 否则
        outsiders.append([name,qq])
        outsiders_mum += 1;
        print ('no')

    count += 1

assert (outsiders_mum == len(outsiders))

print ()
print ("群总人数:" + str(count))
print ("在名单中的人数:" + str(insiders_num))
print ("不在名单中的人数(包含助教):"+str(outsiders_mum))

assert (count == insiders_num + outsiders_mum)

print ()
print ("不在名单中的人如下(群内名称,qq号):")
for mem in outsiders:
    print (mem)

Results are as follows:
Here Insert Picture Description

Published 92 original articles · won praise 2 · Views 3436

Guess you like

Origin blog.csdn.net/zxc120389574/article/details/104347192