Created
April 2, 2019 17:59
-
-
Save shihyu/cafbf8feeb1dbb821084504fcd2c544b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# -*- coding: utf-8 -*- | |
import requests | |
import sys | |
import os | |
import time | |
import sqlite3 | |
from bs4 import BeautifulSoup | |
import pandas as pd | |
def GetHtmlcode(): | |
# Get the webpage's source html code | |
# Header | |
headers = { 'Host' : 'mopsfin.twse.com.tw', | |
'Connection' : 'keep-alive', | |
'Content-Length' : '320', | |
'Accept' : 'text/html, */*; q=0.01', | |
'Origin' : 'http://mopsfin.twse.com.tw', | |
'X-Requested-With' : 'XMLHttpRequest', | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36', | |
'DNT': '1', | |
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8', | |
'Referer' : 'http://mopsfin.twse.com.tw/', | |
'Accept-Encoding' : 'gzip, deflate', | |
'Accept-Language' : 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6', | |
'Cookie' : '_ga=GA1.3.1198519649.1554224754; _gid=GA1.3.1453211674.1554224754; companyId=2101&2006; _gat=1; _gali=setting-fin' } | |
payload = { | |
'compareItem': 'EPSYOY', | |
'quarter': 'true', | |
'ylabel': '%', | |
'ys': '0', | |
'revenue': 'true', | |
'bcodeAvg': 'true', | |
'companyAvg': 'true', | |
'qnumber': '', | |
'companyId': '2101 南港輪胎 (上市橡膠工業)', | |
'companyId': '2006 東和鋼鐵 (上市鋼鐵工業)'} | |
res = requests.post('http://mopsfin.twse.com.tw/', headers=headers, verify=False , data = payload) | |
print(res.text) | |
def main(): | |
page = GetHtmlcode() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment