Skip to content

Instantly share code, notes, and snippets.

@NEJmark
NEJmark / How to trace python code
Last active October 19, 2021 09:40
如何 trace python code
以 requesets 為例
>>> import requests
>>> r=requests.get('https://www.ptt.cc/bbs/movie/index.html')
>>> r.text
到底做了什麼事?
1. 對於一個 module 我們要知道我們使用的原始碼在電腦的哪個位置?
>>> import requests
>>> dir(requests)
['ConnectTimeout', 'ConnectionError', 'DependencyWarning', 'FileModeWarning', 'HTTPError', 'NullHandler', 'PreparedRequest', 'ReadTimeout', 'Request', 'RequestException', 'Response', 'Session', 'Timeout', 'TooManyRedirects', 'URLRequired', '__author__', '__build__', '__builtins__', '__cached__', '__copyright__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__title__', '__version__', '_internal_utils', 'adapters', 'api', 'auth', 'certs', 'codes', 'compat', 'cookies', 'delete', 'exceptions', 'get', 'head', 'hooks', 'logging', 'models', 'options', 'packages', 'patch', 'post', 'put', 'request', 'session', 'sessions', 'status_codes', 'structures', 'utils', 'warnings']
## src: https://stackoverflow.com/questions/21681897/getting-all-attributes-from-an-iwebelement-with-selenium-webdriver
account = "xxx0@gmail.com"
pwd = "xxx"
get_attr = lambda driver, e:driver.execute_script('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', e)
import time,types
from selenium import webdriver
driver = webdriver.Chrome()
driver.get_attr = types.MethodType(get_attr,driver)
driver.get("https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin")
@NEJmark
NEJmark / 盤後交易制度:
Last active May 15, 2017 00:39
盤後交易制度筆記
參考資料:
http://taifex.learn.hinet.net/media.php?vid=1253&type=1
https://www.fubon.com/futures/home/info_content_20170428_343419.htm
盤後交易制度:
1. 5/15 號掛牌(適用)商品:
國內指數: TX(大台指) MTX(小台指) TXO(台指選擇權)
@NEJmark
NEJmark / Nodejs
Created April 15, 2017 01:47
幹這東西真的很雷,預設版本給你舊的
Ubuntu 14.04 雷暴惹:
幹他媽的更新指令
https://askubuntu.com/questions/594656/how-to-install-the-latest-versions-of-nodejs-and-npm-for-ubuntu-14-04-lts/711976#711976
@NEJmark
NEJmark / pipework
Created March 14, 2017 19:15
docker set network
./pipework eth0 ubuntu1 192.168.0.26/24
@NEJmark
NEJmark / uao_decode.py
Last active December 9, 2021 13:14 — forked from andycjw/uao_decode.py
Big5 UAO decodeusage: just do 'import uao_decode.py'unicode_string = big5_string.decode('uao_decode')
# -*- coding: utf-8 -*-
import codecs
import struct
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
u'''
## for example:
## 1. u'築'= \u7bc9, 7bc9(16 進位) = 31689(10進位)
## 2. '築'= '\xbfv'='\xbf\x76'('v'=='\x76'), bf76(16 進位) = 49014
@NEJmark
NEJmark / 財報.py
Last active November 30, 2017 09:16
# -*- coding: utf-8 -*-
import urllib
import lxml.etree as etree
url='http://mops.twse.com.tw/server-java/t164sb01?step=1&CO_ID=2330&SYEAR=2013&SSEASON=1&REPORT_ID=C'
response = urllib.urlopen(url)
html= response.read()
page = etree.HTML(html.decode('cp950'))
item_to_print=[u'基本每股盈餘合計',u'營業收入合計']
for tr in page.xpath('(.//tr[@class="even"]|.//tr[@class="odd"])'):
繁簡轉換
參考:http://www.j4.com.tw/big-gb/
以 str.translate 做簡單的繁簡table轉換,但仍有繁簡字一對多的問題
xpath筆記
股價收盤價抓取練習.py
只能抓取近一個月,因為網站提供資料有限