得到 html
import requests
html=requests.get(\'http://sc.hkex.com.hk/TuniS/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm\').content
解析数据
from pyquery import PyQuery as Q
q=Q(html)
tr = q(\'tr.tr_normal\')
导入 db
db=zpool[\'mysql+mysqldb://root:pwd@dbhost:3306/glhdb\']
sqls = [\"INSERT INTO `stocks_code` (`name`, `code`) VALUES (\'{0}\',\'{1}\')\".format(Q(i)(\'td\')[0].text.encode(\'utf8\',\'ignore\'), ((Q(Q(i)(\'td\')[1])(\'a\') and Q(Q(i)(\'td\')[1])(\'a\')[0].text) or u\'\').encode(\'utf8\',\'ignore\').strip(\')\').strip(\'\\\'\').replace(\'\\\'\',\"\\\\\'\")) for i in tr[0:-3]]
[db.execute(text(i)) for i in sqls]