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
以 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'] |
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
## 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") |
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
參考資料: | |
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(台指選擇權) |
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
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 |
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
./pipework eth0 ubuntu1 192.168.0.26/24 |
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
# -*- 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 |
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
# -*- 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"])'): |
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
繁簡轉換 | |
參考:http://www.j4.com.tw/big-gb/ | |
以 str.translate 做簡單的繁簡table轉換,但仍有繁簡字一對多的問題 |
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
xpath筆記 |
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
股價收盤價抓取練習.py | |
只能抓取近一個月,因為網站提供資料有限 |
NewerOlder