#print res.text
print dir(res)

print res.status_code
print res.headers['content-type']

import requests
payload ={
'StartStation':'977abb69-413a-4ccf-a109-0272c24fd490',
'EndStation':'fbd828d8-b1da-4b06-a3bd-680cdca4d2cd',
'SearchDate':'2015/09/11',
'SearchTime':'14:30',
'SearchWay':'DepartureInMandarin'
}
res = requests.post('https://www.thsrc.com.tw/tw/TimeTable/SearchResult', data = payload)
print res

from datetime import datetime
datetime.strptime('Fri Sep 11 12:56:09 2015', '%y %b %d %H:%M:%S %Y',)

import requests
res = requests.get('http://24h.pchome.com.tw/prod/DRAA0C-A90067G2U')
print res.text

import requests
res = requests.get('http://ecapi.pchome.com.tw/ecshop/prodapi/v2/prod/button&id=DRAA0C-A90067G2U&fields=Seq,Id,Price,Qty,ButtonType,SaleStatus&_callback=jsonp_button?_callback=jsonp_button')
print res.text

"""
Explanation: https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81
End of explanation
"""


# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import  time, re

driver = webdriver.Firefox()
driver.implicitly_wait(3)
base_url = "http://www.agoda.com"

driver.get(base_url + "/zh-tw/city/taipei-tw.html")
driver.find_element_by_id("CheckInMonthYear").click()

driver.implicitly_wait(1)
Select(driver.find_element_by_id("CheckInMonthYear")).select_by_visible_text(u"2015年11月")
driver.implicitly_wait(1)
driver.find_element_by_id("search-submit").click()
driver.implicitly_wait(1)
driver.implicitly_wait(3)
driver.find_element_by_link_text(u"下一頁").click()

"""
Explanation: http://release.seleniumhq.org/selenium-ide/2.9.0/selenium-ide-2.9.0.xpi
End of explanation
"""


from bs4 import BeautifulSoup 
html_sample = ' \
<html> \
<body> \
<h1 id="title">Hello World</h1> \
<a href="#" class="link">This is link1</a> \
<a href="# link2" class="link">This is link2</a> \ </body> \
</html>'
soup = BeautifulSoup(html_sample) 
print soup.text

atag = soup.select('a')
print atag[0]
print atag[1]

print soup.select('#title') # id => #
print soup.select('#title')[0]
print soup.select('#title')[0].text

print soup.select('.link') # class => . 
print soup.select('.link')[0]
print soup.select('.link')[0].text



for link in soup.select('.link'):
    print link.text

a = '<a href="#" qoo="123" abc="456" class="link"> </a>'
soup2 =  BeautifulSoup(a)
print soup2.select('a')
print soup2.select('a')[0]
print soup2.select('a')[0]['href']
print soup2.select('a')[0]['class']
print soup2.select('a')[0]['qoo']
print soup2.select('a')[0]['abc']

for link in soup.select('.link'):
    print link['href']

import requests
from bs4 import BeautifulSoup as bs
res = requests.get('https://tw.stock.yahoo.com/q/h?s=4105')
soup = bs(res.text)
table =  soup.select('table .yui-text-left')[0]
for tr in table.select('tr')[1:]:
    print tr.text.strip()

"""
Explanation: http://phantomjs.org/download.html
http://casperjs.org/
End of explanation
"""


# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import  time, re
from bs4 import BeautifulSoup

driver = webdriver.Firefox()
driver.implicitly_wait(3)

driver.get('http://24h.pchome.com.tw/prod/DRAA0C-A90067G2U')
driver.implicitly_wait(1)
soup = BeautifulSoup(driver.page_source)
print soup.select('#PriceTotal')[0].text
driver.close()

import bs4
print dir(bs4)

from bs4 import BeautifulSoup 
print dir(BeautifulSoup) 

import bs4
doup = bs4.BeautifulSoup(res.text)
#print doup

"""
Explanation: https://chrome.google.com/webstore/detail/infolite/ipjb adabbpedegielkhgpiekdlmfpgal
End of explanation
"""


