lusongno1的博客

生于Code,死于Bug

python练习:疾病专家信息获取工具

  • 做界面如下,编辑信号/槽拉确定到空白,选定accept()

这里写图片描述

  • 存为test.ui。

  • 命令提示符,pyuic4 test.ui -o test.py,转为py文件。

  • 主程序这样写:
# -*- coding: utf-8 -*-
import urllib2
from bs4 import BeautifulSoup
import re
import chardet
import csv
########################################
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
import test
class TestDialog(QDialog,test.Ui_Dialog):  
    def __init__(self,parent=None):  
        super(TestDialog,self).__init__(parent)  
        self.setupUi(self)

app=QApplication(sys.argv)  
dialog=TestDialog()  
dialog.show()  
app.exec_()  
########################################
disease=unicode(dialog.lineEdit.text())
#disease='environmental+illness'
url ='http://expertscape.com/ex/'+disease  
req = urllib2.Request(url)
response = urllib2.urlopen(req)
result = response.read()
response.close()
soup = BeautifulSoup(result)

########################################
country_td= soup.find_all(id="expColTD_c")
country_text = str(country_td)
r_country = re.compile(r',(\d+),".*?,"(.*?)"\)')
country = r_country.findall(country_text)
begin_country=int(country[0][0]);
end_country=int(country[-1][0]);
########################################
city_td= soup.find_all(id="expColTD_t")
city_text = str(city_td)
r_city = re.compile(r',(\d+),".*?,"(.*?)"\)')
city = r_city.findall(city_text)
begin_city=int(city[0][0]);
end_city=int(city[-1][0]);
########################################
institution_td= soup.find_all(id="expColTD_i")
institution_text = str(institution_td)
r_institution = re.compile(r',(\d+),".*?,"(.*?)"\)')
institution = r_institution.findall(institution_text)
begin_institution=int(institution[0][0]);
end_institution=int(institution[-1][0]);
########################################
expert_td= soup.find_all(id="expColTD_a")
expert_text = str(expert_td)
r_expert = re.compile(r',(\d+),".*?,"(.*?)"\)')
expert = r_expert.findall(expert_text)
begin_expert=int(expert[0][0]);
end_expert=int(expert[-1][0]);
########################################
csv = ['SN, FN,CITY,COUNTRY,INSTITUTION\n']
file_name= disease+'_experts.csv'
file_object = open(file_name, 'w+')
for i in range(begin_expert,end_expert+1):
    Et=expert[i- begin_expert][1]
    r_match_indexes_s = re.compile('z\['+str(i)+'\]=\[(.*?)\]')
    match_indexes_s=r_match_indexes_s.findall(result)[0]
    r_city_index=re.compile('')
    match_indexes_n = [int(k) for k in match_indexes_s.split(',')]#这个表达式牛逼
    Cy  = 'none' 
    Cty = 'none'
    In= 'none'
    for index in match_indexes_n:      
        if index>=begin_city and index<=end_city:
            if Cy == 'none':
                Cy=city[index-begin_city][1]
            else:
                Cy=Cy+'&'+city[index-begin_city][1] 
        if   index>=begin_country and index<=end_country and country[index-begin_country][1]!='Worldwide'\
        and country[index-begin_country][1]!='Unspecified' and country[index-begin_country][1]!='Asia'\
        and  country[index-begin_country][1]!='Europe':
            if Cty == 'none':
                Cty=country[index-begin_country][1]
            else:
                Cty=Cty+'&'+country[index-begin_country][1] 
        if  index>=begin_institution and index<=end_institution:
            if In == 'none':
                In=institution[index-begin_institution][1]
            else:
                In=In+'&'+institution[index-begin_institution][1]            
    info=Et+','+Cy.replace(",","_")+','+Cty.replace(",","_")+','+In.replace(",","_")+'\n'
    info=info.decode('utf-8').encode('mbcs')
    csv.append(info)
file_object.writelines(csv)
file_object.close()



  • 转成exe===>>>因用了pyQT做界面,setup.py这样写:
from distutils.core import setup
import py2exe
setup(console=[{"script":"英文式主程序名.py"}], options={"py2exe":{"includes":["sip"]}})


打开终端运行setup.py py2exe ,咻的一下就出来了。

重复性工作,电子记录,做个存档而已。哪里都是 随意,随意。。。

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lusongno1/article/details/53984688
文章标签: python 界面 utf-8 csv
个人分类: 前端与python
上一篇安卓装逼技巧:QQ空间变iPhone8客户端
下一篇matlab如何在文中定义函数
想对作者说点什么? 我来说一句

联系高德API租房

2017年03月13日 30KB 下载

常见疾病诊断专家系统

2015年10月02日 421KB 下载

最全ICD-10疾病编码

2018年02月09日 1.73MB 下载

没有更多推荐了,返回首页

关闭
关闭