import requests
from lxml import etree

def getZs(realname, ID_number):
    payload = {'IndexModel[name]': realname, 'IndexModel[identityNumber]': ID_number, 'IndexModel[certNumber]':'', 'IndexModel[candidateNumber]':''}
    r = requests.post('https://fushe.chinansc.cn/open/candidate-list',data=payload)
    html = etree.HTML(r.text)
    results = html.xpath("//table[@class='cert-table']")
    candidates = []
    try:
        for i in results:
            img = i.xpath('tr/td/a/@href')
            name = i.xpath('tr[1]/td[1]/text()')
            ID_number = i.xpath('tr[1]/td[2]/text()')
            report_number = i.xpath('tr[2]/td[1]/text()')
            issue_date = i.xpath('tr[2]/td[2]/text()')
            jsondata = {
                'name':name[0],
                'ID_number':ID_number[0],
                'report_number':report_number[0],
                'issue_date':issue_date[0],
                'img':'https://kaowu.chinansc.cn'+ img[0]
                }
            candidates.append(jsondata)
    except:
        pass
    return candidates