#
!/usr/bin/python2.4
#
-*- coding: utf8 -*-
#
Ifeng Site
#
import
codecs,time
from
SeleniumUtil
import
SeleniumUtil
ExchangeUrlMap
=
{
"
CCS
"
:
"
http://app.finance.ifeng.com/list/usstock_cn.php
"
,
#
"SHA_B": "http://stock.finance.sina.com.cn/stock/quote/shb%s.html",
}
ExchangeXPath
=
"
//html/body/div[4]/div/div[2]/div/table/tbody/tr[%s]/td[1]
"
class
IfengFinanceSite:
#
result file for diff exchanges
def
GetAllTickers(self, exchange, resultFiles):
sln
=
SeleniumUtil().GetSelenium(
"
Ifeng
"
,
"
http://app.finance.ifeng.com/
"
)
myfile
=
codecs.open(resultFiles
%
exchange,
'
w
'
,
'
utf-8
'
)
count
=
0
sln.open(ExchangeUrlMap[exchange])
time.sleep(
5
)
for
j
in
range(
2
,
200
):
if
sln.is_element_present(ExchangeXPath
%
j):
context
=
sln.get_text(ExchangeXPath
%
j).strip()
print
>>
myfile, context,
'
\r
'
count
=
count
+
1
else
:
break
print
"
%s companies for exchange %s recorded.
"
%
(count, exchange)
sln.stop()
exchangelist
=
[
"
CCS
"
]
#
"SHA_A","SHA_B","SHE_A","SHE_B","SHA_Q","SHA_CEF","SHE_CEF","SHA_Bond","SHE_Bond"
for
exchange
in
exchangelist:
print
exchange
resultFiles
=
"
Ifeng_company_list_%s.txt
"
IfengFinanceSite().GetAllTickers(exchange, resultFiles)