2016年6月24日 星期五

BeautifulSoup4

$ pip install beautifulsoup4

BeautifulSoup4中文介紹
https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/

四種用法
Python標準庫
BeautifulSoup(markup, "html.parser")
lxml HTML 解析器
BeautifulSoup(markup, "lxml")
lxml XML 解析器
BeautifulSoup(markup, ["lxml", "xml"])
BeautifulSoup(markup, "xml")
html5lib
BeautifulSoup(markup, "html5lib")

幾個簡單的瀏覽結構化數據的方法:

soup.title
# <title>The Dormouse's story</title>

soup.title.name
# u'title'

soup.title.string
# u'The Dormouse's story'

soup.title.parent.name
# u'head'

soup.p
# <p class="title"><b>The Dormouse's story</b></p>

soup.p['class']
# u'title'

soup.a
# <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>

soup.find_all('a')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
# <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

soup.find(id="link3")
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>



for link in soup.find_all('a'):
print(link.get('href'))
# http://example.com/elsie
# http://example.com/lacie
# http://example.com/tillie



print(soup.get_text())
# The Dormouse's story
#
# The Dormouse's story
#
# Once upon a time there were three little sisters; and their names were
# Elsie,
# Lacie and
# Tillie;
# and they lived at the bottom of a well.
#
# ...

2016年6月23日 星期四

高鐵POST擷取分析

  • Request URL:https://irs.thsrc.com.tw/IMINT/?wicket:interface=:1:BookingS1Form:1:IFormSubmitListener
  • Request Method:POST

GoogleChrome/開發人員工具/Network \\Headers:

  1. Request URL:https://www.gay-torrents.net/search.php?do=process
  2. Request Method:POST
  1. BookingS1Form:hf:0:
  2. selectStartStation:1
  3. selectDestinationStation:11
  4. trainCon:trainRadioGroup:0
  5. bookingMethod:radio20
  6. toTimeInputField:2016/07/21
  7. toTimeTable:230P
  8. toTrainIDInputField:
  9. backTimeInputField:2016/07/21
  10. backTimeTable:
  11. backTrainIDInputField:
  12. ticketPanel:rows:0:ticketAmount:1F
  13. ticketPanel:rows:1:ticketAmount:0H
  14. ticketPanel:rows:2:ticketAmount:0W
  15. ticketPanel:rows:3:ticketAmount:0E
  16. offPeakTrainSearchContainer:onlyQueryOffPeak:on
  17. homeCaptcha:securityCode:TANF
  18. SubmitButton:開始查詢




  1. Request URL:https://www.gay-torrents.net/search.php?do=process
  2. Request Method:POST

回應的標頭

    1. Cache-Control:private
    2. Content-Encoding:gzip
    3. Content-Length:9324
    4. Content-Type:text/html; charset=UTF-8
    5. Date:Fri, 24 Jun 2016 06:30:11 GMT
    6. Pragma:private
    7. Server:lighttpd/1.4.39


淘寶GET擷取分析

開啟淘寶首頁進行搜尋:皮繩

GoogleChrome/開發人員工具/Network

Headers:

  1. Request URL:
    https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910789
  2. Request Method:GET

發現他是使用 HTTP請求 裡面的GET

Postman可以確認Request URL細節
https://www.getpostman.com/docs/install_mac

打開Jupyter

new 一個Python2的py檔

In[1]:

import requests

res = requests.get("https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910789")

print res.text


chrome套件

SelectorGadget

https://chrome.google.com/webstore/detail/selectorgadget/mhjhnkcfbdhnjickkkdbjoemdmbfginb?hl=zh-TW


用Safari檢閱按右鍵檢視元件更快


在class="grid"的div

有0~43共44個方格子
每個方格子都是一個,data-index="0"中的數字為編號0~43
<div class="item " data-category="auctions" data-index="0">….</div>

圖片
data-spm-anchor-id="a230r.1.14.1"

圖上雙橘按鈕區塊 div.similars
找同款data-spm-anchor-id="a230r.1.14.2"
找相似data-spm-anchor-id="a230r.1.14.3"
價格.g_price strong
幾人收貨:class="deal-cnt"

圖片的屬性:
ClassName= J_ItemPic img

baseURI: "https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910…"

alt 送銀扣蠟皮繩水晶吊墜項鏈掛繩男女手工編織黃金翡翠玉珮黑紅繩子
class J_ItemPic img
id J_Itemlist_Pic_38694171862
data-src//g-search2.alicdn.com/img/bao/uploaded/i4/i3/TB1wDPVFVXXXXX.XFXXXXXXXXXX_!!0-item_pic.jpg
src //g-search2.alicdn.com/img/bao/uploaded/i4/i3/TB1wDPVFVXXXXX.XFXXXXXXXXXX_!!0-item_pic.jpg_460x460Q90.jpg

jupyter notebook ( ipython notebook) mac

開啟 終端機
option+空白鍵 選 iTerm(或 終端機)
安裝 Jupyter
$ pip install jupyter

造 一個 jupyter資料夾
$mkdir Jupyter
切換 至 jupyter資料夾下
$cd Jupyter
iTerm輸入
$jupyter notebook
預設瀏覽器會開啟一個 http://localhost:8888

Requests pip install mac

Requests|URLs擷取套件

python2.7
$ pip install requests

python3
$ pip3 install requests

Beautifulsoup4 python2.7 mac

首先從package的網站上下載最新版的package

https://pypi.python.org/pypi/beautifulsoup4

然後你會得到一個壓縮包名叫beautifulsoup4-4.4.1.tar.gz。

解壓至桌面

接著打開終端,開始切換至解壓的文件夾

cd Desktop
cd beautifulsoup4-4.4.1

接著告訴python安裝這個package

sudo python ./setup.py install

五術

五術|山、醫、命、卜、相
| 三術 |
源自易經(涵蓋宇宙時空萬物=陰陽相對+相互轉化
ex冬去春來,夏去秋來,月升日落,老死少生

山( = 仙 )
1st 玄典| 《老子》、《莊子》、《列子》、《孫子》、《太公陰符經》、《黃帝內經》、《道藏》
exp:《西遊記》
2nd養生| 氣功|長壽吐納法
道家 煉丹法|天丹、人丹、地丹
3rd 修密|符咒法、壓鎮法、祈星法、武術(運動、精神、意念統一)


方劑|藥物(表裏、虛實、寒熱)+周易八卦|ex:陰極生陽,陽極生陰
針灸|銅針、穴位《黃帝內經》、《難經》辯奇經八脈、穴道
靈療|催眠、暗示、集中意念,利用做藥引來治療疾病的方法。


占卜「人」,判斷命運=時間+空間磁場
「斷易推命」、「六壬推命」、「奇門推命」、「太乙推命」只是占術應用
占星術|《七政四余》、《紫薇斗數》、《五星術》。
干支術|《果老星宗》、《星平會海》、《淵海子平》、《鬼谷遺文》、《孫臏遺書》、《三命通會》、《窮通寶鑑》(欄江綱)、《滴天髓》、《神峰通考》、《鐵板神數》、《河洛理數》、《子平真詮》、《子平粹言》


數術玄學、軍事家(漢朝的諸葛亮、唐朝的李淳風、宋朝的邵康節、明朝的劉伯溫、清朝的曾國藩)
卜派|《梅花易數》、《納甲斷易》、《六壬神課》、《太乙神數》、《奇門遁甲》
包含 預言、克應占夢、測字解字、簽貼、姓名學
術數|=數術
觀天象|漢代流行,推測國運、個人吉凶《漢書‧藝文誌》內《數術略》,為七略
《數術略》| 天文、歷譜、五行、蓍龜、雜佔、形法

印相|印章上文字吉凶
名相|字、音、形、五行 的 吉凶方術
人相|面相是
手相是來推算吉凶。

人相|手相|以掌為中心,以十天乾和星球間之關係理論
面相|以面為中心,以十二地支及星球理論來推算吉凶。
體相、摸骨、痣相|《觀人於微》、《相理衡真》、《神相鐵關刀》

《水鏡神相》、《麻衣神相》、《金鉸剪》
地相|=《堪輿術》 陽宅相法|看門井灶
(墓地=風水術)陰宅相法 |看龍穴砂水向
派別|《三元法》、《三合法》、《九星法》