Skip to content

Instantly share code, notes, and snippets.

@davidyen1124 davidyen1124/kgi.py

Created Feb 18, 2014
Embed
What would you like to do?
kgi
import requests
import re
url = "https://www.kgieworld.com.tw/stock/stock_2_7.aspx?findex=1"
def main():
session = requests.session()
response = session.get(url)
content = response.content
if content:
payload = {'__EVENTTARGET': 'lbtnDown01',
'selMarket': 1,
'__EVENTVALIDATION': get_hidden_value('__EVENTVALIDATION', content),
'__VIEWSTATE': get_hidden_value('__VIEWSTATE', content)}
response = session.post(url, payload)
content = response.content
if content:
with open("kgi.xls", "wb") as f:
f.write(content)
def get_hidden_value(id, content):
value = ''
match = re.search(r'id="%s" value="(.*?)"' % (id), content)
if match:
value = match.group(1)
return value
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.