goodinfo
import requests
from bs4 import BeautifulSoup
import csv
import sys
import pandas as pd
reload(sys)
sys.setdefaultencoding('utf-8')
def GetHtmlcode(ID):
source = 'http://goodinfo.tw/StockInfo/StockDetail.asp?STOCK_ID='
url = source + ID
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'}
res = requests.get('http://goodinfo.tw/StockInfo/StockDetail.asp?STOCK_ID=2103', headers=headers)
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text.replace(' ', '').replace(' ',''), 'lxml')
return soup
def main():
soup = GetHtmlcode('2324')
for head in soup.select('.head_td b'):
if head.text == u'合併獲利狀況':
df = pd.read_html(str(head.parent.parent.parent.parent), encoding = "UTF-8")
df2=pd.DataFrame(df[0])
df2 = df2[2:]
df2.columns = df2.iloc[0]
df2 = df2.drop(df2.index[0])
df2.columns.name = ''
df2.index = range(len(df2))
print df2
if __name__ == "__main__":
main()
import re
import urllib2
import csv
import pandas as pd
def GetHtmlcode(ID):
source = 'http://goodinfo.tw/StockInfo/StockDetail.asp?STOCK_ID='
url = source + ID
headers = { 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset' : 'Big5,utf-8;q=0.7,*;q=0.3',
'Accept-Language' : 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2' ,
'Cache-Control' : 'max-age=0',
'Connection' : 'keep-alive',
'Cookie' : '427 bytes were stripped',
'Host' : 'www.goodinfo.tw',
'Referer' : url }
req= urllib2.Request(url,"",headers)
response = urllib2.urlopen(req)
result = response.read().decode('utf-8')
return result
def main():
page = GetHtmlcode('2103')
df=pd.read_html(page)
df2=pd.DataFrame(df[41])
df2 = df2[2:]
df2.columns = df2.iloc[0]
df2 = df2.drop(df2.index[0])
df2.columns.name = ''
df2.index = range(len(df2))
print df2
if __name__ == "__main__":
main()
import re
import urllib2
import csv
import pandas as pd
def GetHtmlcode(ID):
source = 'http://goodinfo.tw/StockInfo/StockDetail.asp?STOCK_ID='
url = source + ID
headers = { 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset' : 'Big5,utf-8;q=0.7,*;q=0.3',
'Accept-Language' : 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2' ,
'Cache-Control' : 'max-age=0',
'Connection' : 'keep-alive',
'Cookie' : '427 bytes were stripped',
'Host' : 'www.goodinfo.tw',
'Referer' : url }
req= urllib2.Request(url,"",headers)
response = urllib2.urlopen(req)
result = response.read().decode('utf-8')
return result
def main():
page = GetHtmlcode('2103')
df=pd.read_html(page)
for i in range(len(df)):
print type(df[i].loc[0,0])
if df[i].loc[0,0] == u"獲 利 狀 況 (/)":
print i
if __name__ == "__main__":
main()