In [1]:
import requests
res = requests.get('https://www.python.org/')
print res


<Response [200]>

In [4]:
#print res.text
print dir(res)


['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url']

In [5]:
print res.status_code
print res.headers['content-type']


200
text/html; charset=utf-8

In [7]:
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


<Response [200]>

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


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-a16155821adc> in <module>()
      1 from datetime import datetime
----> 2 datetime.strptime('Fri Sep 11 12:56:09 2015', '%y %b %d %H:%M:%S %Y',)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.pyc in _strptime(data_string, format)
    323     if not found:
    324         raise ValueError("time data %r does not match format %r" %
--> 325                          (data_string, format))
    326     if len(data_string) != found.end():
    327         raise ValueError("unconverted data remains: %s" %

ValueError: time data 'Fri Sep 11 12:56:09 2015' does not match format '%y %b %d %H:%M:%S %Y'

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


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="content-language" content="zh-tw">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>PChome線上購物 - </title>
<META name="author" content="PChome線上購物">
<META id="MetaKeywords" NAME="keywords" CONTENT="">
<META id="MetaDescription" NAME="description" CONTENT="">
<meta property="og:title" id='ogtitle' content=""/>
<meta property="og:type" id='ogtype' content="product"/>
<meta property="og:image" id='ogimage' content=""/>
<meta property="og:url" id='ogurl' content=""/>
<meta property="og:description" id='ogdesc' content=""/>
<meta property="og:site_name" content="PChome 24h購物"/>
<meta name="copyright" content="網路家庭版權所有、轉載必究 ● Copyright PChome Online">
<meta name="robots" content="NOODP">
<link id="canonical" rel="canonical" href="">
<link id="css" name="h24css" type="text/css" href="/min/g=prodh24cssv2&20150901" rel="stylesheet">
<script type="text/javascript" async src="/min/g=prodjsv2&20150910"></script>
</head>
<body>
<dl id="nc17Container"  style="display:none">
    <dt><!-- 敬告啟示-未成年者(註)請勿瀏覽及購買本館商品,本網站已依台灣網站內容分級規定處理。註:以當地國家法律規定之成年年齡為準。 --></dt>
    <dd><a class="ico forbid" href="javascript:void(0);"><!-- 我未滿18歲,禁止進入 --></a></dd>
    <dd><a class="ico allow" href="javascript:void(0);"><!-- 我已滿18歲,進入本館 --></a></dd>
</dl>
<div id="GLOBALWRAPPER" class="prod_w" style="display:none">
    <div id="WRAPPER" class="style_h24">
    <!-- HEADER start -->
<div id="HEADER">
<div class="clearfix">
<h1 class="logotype left"><a class="prod" href="http://24h.pchome.com.tw">PChome 24h購物</a></h1>
<div class="site_tool relative">
<sup></sup>
  <ul class="bar_nav absolute">
    <li><a href="http://shopping.pchome.com.tw">線上購物</a></li>
    <li><a href="http://24h.pchome.com.tw">24h購物</a></li>
    <li><a href="http://mall.pchome.com.tw">購物中心</a></li>
    <li><a href="/book">書店</a></li>
    <li><a class="sp" href="http://global.pchome.com.tw">全球購物</a></li>
  </ul>
  <ul class="bar_service absolute">
    <li><a href="http://shopping.pchome.com.tw/?mod=store&func=choice_buy&page_url=shopping&NO=D&C=D" class="cart sp" accesskey="B" title="點擊後進入結帳清單">購物車</a></li>
    <li><a href="https://ecvip.pchome.com.tw">顧客中心</a></li>
    <li><a href="https://ecvip.pchome.com.tw/?m=vendor" >廠商合作</a></li>
    <li><a href="https://ecvip.pchome.com.tw/?m=myaccount&c=service&f=showBugService&url=aHR0cDovLzI0aC5wY2hvbWUuY29tLnR3L3NpZ24vM2MuaHRt">故障通報</a></li>
    <li><a href="http://www.pchome.com.tw/">PChome</a></li>
  </ul>
</div>
</div>
<div class="block_H relative">
<dl class="h1 absolute">
  <dd id="24hrFeeContainer"><p class="absolute "><small>購物滿$490</small>免運費</p></dd>
  <dd id="SearchContainer" class="bar_search site_corner cor1px">
        <sup class="l"></sup><sup class="r"></sup>
        <sub class="l"></sub><sub class="r"></sub>
        <label for="keyword" class="unblock">搜尋框,請輸入關鍵字後按enter查詢</label><input accesskey="S" placeholder="請輸入關鍵字" type="text" id="keyword" class="text left"  x-webkit-speech="" x-webkit-grammar="builtin:translate" />
        <input type="button" id='doSearch'  class="button" value="找商品" />
    </dd>
  <dd class="absolute sp"><a href="https://ecvip.pchome.com.tw/?m=myaccount&c=service&f=showSearchService">買不到通知我</a></dd>
  <dd class="bar_account"><a href="https://ecvip.pchome.com.tw">顧客中心(查訂單、退貨、客服)</a></dd>
  <dd id="shopAd220Container" class="site_ad unblock"><a href=""><img src="" alt=""/></a></dd>
</dl>
<div id="site_roadsign" class="h2 absolute"></div>
<div class="h3 absolute">
<div class="site_tooth"></div>
</div>
</div>
</div>
<!-- HEADER end -->
        <!-- CONTENT start -->
        <div id="CONTENT" class="clearfix">
            <!-- block_N start -->
            <div class="block_N">
                <sup></sup>
                <sub></sub>
                <h3><a id="StoreName" href="javascript:void(0);"></a></h3>
                <a id="shopAd500Container" class="site_ad unblock" href=""><img src="" alt=""/></a>
                <div class="info">
                <div id=debug></div>
                    <b class="b1f"></b>
                    <ul>
                        <li class="sp">‧台北巿6小時到貨(試營運)</li>
                        <li>‧全台灣24小時到貨,遲到給100</li>
                        <li>‧非北北基22:00~10:00間下單、離島、資訊不完整、<br/> 新客、安裝商品、ATM或 ibon付款者等不在此限<a href="http://shopping.pchome.com.tw/?m=sitemap&func=24h" target="_blank">→說明</a></li>
                    </ul>
                    <b class="b1f"></b>
                </div>
                <!--購物車 start-->
               <div id="24hrCartContainer" class="cart cart_1">
                    <span class="price"><span class="value">$0</span></span>
                    <a class="number" href="http://shopping.pchome.com.tw/?mod=store&func=choice_buy&page_url=shopping&NO=D&C=D">(<span>0</span>)</a>
                    <a class="check" href="http://shopping.pchome.com.tw/?mod=store&func=choice_buy&page_url=shopping&NO=D&C=D">結帳&gt;</a>
                </div>

                <!--購物車 end-->
                <ul id="LinkContainer" class="path">
                    <li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="http://www.pchome.com.tw/" itemprop="url"><span itemprop="title">PChome</span></a> &gt;</li>
                    <li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="http://shopping.pchome.com.tw/" itemprop="url"><span itemprop="title">線上購物</span></a> &gt;</li>
                    <li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"></li>
                    <li class="unblock" itemscope itemtype="http://data-vocabulary.org/Breadcrumb" id='linkRegion'></li>
                    <li class="unblock" itemscope itemtype="http://data-vocabulary.org/Breadcrumb" id='linkStore'></li>
                </ul>
            </div>
            <!-- block_N end -->
             <!-- block_W sidebar start -->
            <div class="block_W sidebar">
                <sup></sup>
                <!-- store_list start -->
                <dl class="store_list">
                    <dt id="RegionName"></dt>
                    <dd>
                        <dl id="StoreContainer"></dl>
                    </dd>
                </dl>
                <!-- store_list end -->
                <!-- hot_list start -->
                <dl id="SaleContainer" class="hot_list unblock">
                </dl>
                <!-- hot_list end -->
              </div>
            <!-- block_W sidebar end -->
            <!-- block_c start -->
            <div class="block_C">
                <!-- prod_list start -->
                <dl class="prod_list" itemscope itemtype="http://schema.org/Product">
                    <dd id="StoreAd800Container" class="unblock"><a class="site_ad" href="" target="_blank"><img src="" alt=""/></a></dd>
                    <dd  id="NameContainer" class="Ct clearfix"></dd>
                    <dd class="clearfix">
                        <!-- Cl start -->
                        <div class="Cl">
                            <div id="BonusContainer" class="bar_bonus site_corner cor1px unblock">
                                <sup class="l"></sup>
                                <sup class="r"></sup>
                                <sub class="l"></sub>
                                <sub class="r"></sub>
                                <span>
                                    <b>送</b>單品加碼金:<i>0</i>點
                                    <a href="/html/BADD_help.html" title="1.加碼金使用方式及規則同現金積點。 2.加碼金不適用任何現金積點倍數送活動。" >說明</a>
                                </span>
                            </div>
                            <div id="ImgContainer" class="prod_img"></div>
                            <ul id="UpAndDownContainer" class="bar_prodnav unblock">
                            </ul>
                            <dl id="SPFInfoContainer" class="msg unblock">
                                <dt>※</dt>
                                <dd>消費者同意,此預購型商品發生缺貨或貨源不足..等情形、致網路家庭無法出貨時,此商品預購契約不成立</dd>
                            </dl>
                            <!-- prod_combo start -->
                            <dl id="CombineContainer" class="prod_combo unblock">
                                <dt>搭配商品:</dt>
                            </dl>
                            <!-- bar_combo end -->
                        </div>
                        <!-- Cl end -->
                        <!-- Cr start -->
                        <div class="Cr">
                            <!-- prod_descrb start -->
                            <!-- prod_descrb -->
                            <div id="DescrbContainer" class="prod_describe clearfix">
                                <ul class="right">
                                <!-- h24區塊 -->
                                <li id="h24Block"></li>
                                </ul>
                                <div class="left">
                                    <div id="MarketingContainer" class="bar_gift"><ul>
                                        <li id="MarketingBonus" class="popupOn unblock"><a href="#">
                                            <span class="sign">現金積點</span>
                                            <div></div>
                                            <span class="more">(詳)</span>
                                            <span class="note">止</span>
                                        </a></li>
                                        <li id="MarketingActivity" class="unblock"><a href="#">
                                            <span class="sign">折扣活動</span>
                                            <div></div>
                                            <span class="note">止</span>
                                        </a></li>
                                        <li id="MarketingRaiseBonus" class="popupOn unblock"><a href="#">
                                            <span class="sign">加碼金</span>
                                            <div></div>
                                            <span class="more">(詳)</span>
                                            <span class="note">止</span>
                                        </a></li>
                                        <li id="MarketingGift" class="popupOn unblock"><a href="#">
                                            <span class="sign">滿額贈</span>
                                            <div></div>
                                            <span class="more">(詳)</span>
                                            <span class="note">止</span>
                                        </a></li>
                                    </ul><span id="moreMarketing" class="ui-btn-collapsible unblock">展開</span></div>
                                    <div class="slogan">
                                        <div id="ActivityContainer" class="bar_event unblock">
                                            <sup></sup>
                                            <sub></sub>
                                            <span><b>活動商品:</b><a href="javascript:void(0);"></a></span>
                                        </div>
                                        <p id="ExtraContainer" class="title sp unblock"></p>
                                        <p id="NickContainer" class="title clearfix"></p>
                                        <div id="SloganContainer"></div>
                                        <ul id="BookInfoContainer" class="sp"></ul>
                                    </div>
                                </div>
                            </div>
                            <!-- prod_descrb end -->
                            <!-- prodPayway start -->
                           <div id="PaymentContainer" class="prod_payway clearfix"  itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                            </div>
                            <!-- prodPayway end -->
                                  <!-- bar_bonus start -->
                            <div id='BonusInfoContainer' class="bar_bonus unblock">
                                <p>送單品加碼金<i>0</i>點<a href="http://shopping.pchome.com.tw/?m=item&f=bonus_help" target="_blank">說明</a><span>(1點 = 1元)</span></p>
                                <span>(限使用貨到付款、ATM、7-11 ibon、金融卡即時轉帳、信用卡1、3、6期可獲得)</span>
                            </div>
                            <!-- bar_bonus end -->
                            <dl class="site_timer">
                                <dt></dt>
                                <dd>您約在<div class="timer"><span class="min"></span><span class="sec"></span></div>後可進入搶購流程</dd>
                            </dl>

                             <div id="ButtonContainer" class="site_btn tr">
                            </div>
                             <!-- prod_gift start -->
                            <dl id="AddContainer" class="prod_gift sp unblock">
                                <dt>加購商品:</dt>
                                <dd class="clear_magi">
                                    <ol>
                                    </ol>
                                </dd>
                                <dd class="tr clear_line">
                                    <p><a href="javascript:void(0);">看更多&gt;</a></p>
                                </dd>
                            </dl>
                            <!-- prod_gift end -->
                            <!-- prod_gift start -->
                            <dl id="GiftContainer" class="prod_gift unblock">
                                <dt>贈品:</dt>
                                <dd>
                                    <ol>
                                    </ol>
                                </dd>
                            </dl>
                            <!-- prod_gift end -->
                        </div>
                    </dd>
                    <dd class="Cb clearfix">
                         <dl id="GiftListContainer" class="prod_gift">
                        </dl>
                        <!-- prod_gift end -->
                        <!-- prod_option start -->
                        <dl id="GiftListPicContainer" class="prod_option clearfix">
                        </dl>
                         <dl class="prod_recommend unblock" id='AlsoViewAndBuyContainer'>
                            <dd class="head clearfix">
                                <ul class="tab_box">
                                    <li id='AlsoView'><a href="javascript:void(0)">看此商品的人也看了...</a><sup></sup><sub></sub></li>
                                    <li id='AlsoBuy'><a href="javascript:void(0)">買此商品的人也買了...</a><sup></sup><sub></sub></li>
                                </ul>
                            </dd>
                            <dd  class="body clearfix">
                                <a href="javascript:void(0)"  style = "outline:none" class='left'><span class="ico prev">上一頁</span></a>
                                <div class="list">
                                    <dl id="AlsoBody" class="clarfix site_looplist vc_120">
                                    </dl>
                                </div>
                                <a href="javascript:void(0)"  style = "outline:none" class='right'><span class="ico next">下一頁</span></a>
                            </dd>
                        </dl>
                        <p class="line_dotted">&nbsp;</p>
                        <dl id='StoreProdAd800Container' class="unblock"><a class="site_ad" href="" target="_blank"><img src="" /></a></dl>
                        <!-- prod_intro start -->
                        <dl id='IntroContainer' class="prod_intro unblock">
                        </dl>
                         <!-- prod_intro end -->
                        <!-- site_btn start -->
                        <div class="site_btn tc">
                        </div>
                        <!-- site_btn end -->
                        <p class="line_dotted">&nbsp;</p>

                        <!-- prod_add start -->
                        <dl id="MoreAddContainer" class="prod_add unblock">
                            <dt>加購專區</dt>
                            <dd class="tr">
                                <a id ="top" href="javascript:void(0)">△回TOP</a>
                            </dd>
                        </dl>
                        <!-- prod_add end -->
                        <!-- site_btn start -->
                        <div class="site_btn tc">
                        </div>
                        <!-- prod_info start -->
                        <p class="line_dotted">&nbsp;</p>
                        <!-- prod_info start -->
                        <dl id="EquipContainer" class="prod_info site_corner unblock">
                            <dd>
                                <dl>
                                    <dt>本商品標準配備 + 贈品</dt>
                                    <dd  id="Equiphtml">
                                    </dd>
                                </dl>
                                <sup class="l"></sup>
                                <sup class="r"></sup>
                                <sub class="l"></sub>
                                <sub class="r"></sub>
                            </dd>
                        </dl>
                        <!-- prod_info end -->
                        <!-- prod_info start -->
                        <dl id="StmtContainer" class="prod_info site_corner unblock">
                            <dd>
                                <dl>
                                    <dt>本商品規格</dt>
                                    <dd  id="Foodhtml">
                                    </dd>
                                    <dd  id="Stmthtml">
                                    </dd>
                                </dl>
                                <sup class="l"></sup>
                                <sup class="r"></sup>
                                <sub class="l"></sub>
                                <sub class="r"></sub>
                            </dd>
                        </dl>
                        <!-- prod_info end -->
                        <!-- prod_info start -->
                      <dl id="RemarkContainer" class="prod_info site_square unblock">
                       </dl>
                        <!-- prod_info end -->
                        <!-- site_btn start -->
                        <div class="site_btn tc">
                        </div>
                        <!-- site_btn end -->
                        <p class="line_dotted">&nbsp;</p>
                        <!-- shop_info start -->
                        <dl id="WarrantyContainer" class="shop_info unblock">
                            <dt>運送及保固說明
                            <b class="ico shipping">配送到府</b>
                            </dt>
                            <dd class="site_corner">
                                <dl class="clearfix">
                                </dl>
                                <sup class="l"></sup>
                                <sup class="r"></sup>
                                <sub class="l"></sub>
                                <sub class="r"></sub>
                            </dd>
                        </dl>
                        <dl class="shop_info">
                            <dt>商品退貨需知<b class="ico return">退貨免費,到府收貨</b></dt>
                            <dd class="site_corner">
                                <dl class="clearfix">
                                    <dt>關於退貨:</dt>
                                    <dd>PChome Online線上購物的消費者,都可以依照消費者保護法的規定,享有商品貨到次日起七天猶豫期的權益。但猶豫期並非試用期,請留意,您所退回的商品必須回復原狀(須回復至商品到貨時的原始狀態)並且保持完整包裝(包括商品本體、配件、贈品、保證書、原廠包裝及所有附隨文件或資料的完整性),切勿缺漏任何配件或損毀原廠外盒。<br/>
如果您所購買的商品是電腦軟體、遊戲光碟、CD、VCD、DVD、食品、耗材、個人衛生用品等一經拆封即無法回復原狀的商品,在您還不確定是否要辦理退貨以前,請勿拆封。<br/>
若您需辦理退貨,請利用顧客中心「查訂單」或「退訂/退款查詢」的「退訂/退貨」功能填寫申請,我們將於接獲申請之次日起1個工作天內檢視您的退貨要求,檢視完畢後將以E-mail回覆通知您,並將委託本公司指定之宅配公司,在5個工作天內透過電話與您連絡前往取回退貨商品。請您保持電話暢通,並備妥原商品及所有包裝及附件,以便於交付予本公司指定之宅配公司取回(宅配公司僅負責收件,退貨商品仍由特約廠商進行驗收),宅配公司取件後會提供簽收單據給您,請注意留存。<br/>
退回商品時,請以本公司或特約廠商寄送商品給您時所使用的外包裝(紙箱或包裝袋),原封包裝後交付給前來取件的宅配公司;如果本公司或特約廠商寄送商品給您時所使用的外包裝(紙箱或包裝袋)已經遺失,請您在商品原廠外盒之外,再以其他適當的包裝盒進行包裝,切勿任由宅配單直接粘貼在商品原廠外盒上或書寫文字。<br/>
提醒您,原廠外盒及原廠包裝都屬於商品的一部分,若有遺失、毀損或缺件,可能影響您退貨的權益,也可能依照損毀程度扣除為回復原狀所必要的費用。<br/>
若因您要求退貨或換貨、或因本公司無法接受您全部或部分之訂單、或因契約解除或失其效力,而需為您辦理退款事宜時,您同意本公司得代您處理發票或折讓單等相關法令所要求之單據,以利本公司為您辦理退款。<br/>
本公司收到您所提出的申請後,若經確認無誤,將依消費者保護法之相關規定,返還您已支付之對價(含信用卡交易),退款日當天會再發送E-mail通知函給您。<br/>
                                    </dd>
                                </dl>
                                <sup class="l"></sup>
                                <sup class="r"></sup>
                                <sub class="l"></sub>
                                <sub class="r"></sub>
                            </dd>
                        </dl>
                        <!-- shop_info end -->
                         <!-- site_btn start -->
                        <div class="site_btn tc">
                        </div>
                        <!-- site_btn end -->
                    </dd>
                    <!-- Cb end -->
                </dl>
                <!-- prod_list end -->
            </div>
            <!-- block_C end -->
            <!-- block_S bt_top start -->
            <div class="block_S bt_top">
                <a class ='gototop' href="javascript:void(0)">△回TOP</a>
            </div>
            <!-- block_S bt_top end -->
        </div>
        <!-- CONTENT end -->
        <!-- FOOTER start -->
        <div id="FOOTER">
            <p><a href="http://shopping.pchome.com.tw/">PChome線上購物</a><b>-</b>網路家庭國際資訊股份有限公司 版權所有‧轉載必究<a class="sp" href="http://faq.pchome.com.tw/faq_solution.html?q_id=16&c_nickname=member&f_id=4">隱私權聲明</a><a class="fc-white" href="http://shopping.pchome.com.tw/?mod=sitemap&amp;func=sitemap" accesskey="M" title="網站導覽">:::</a></p>
            <p>106 台北市大安區敦化南路二段105號12樓 電話(上班時間):02-2326-1460<span>(本公司不會以此電話號碼撥打給您,如有來電顯示此號碼,請勿理會)</span></p>
            <p class="sp">PChome and PChome Online are trademarks of PChome Online Inc.</p>
        </div>
        <!-- FOOTER end -->


        <!--購物車 start-->
        <div id="CarInfo" class='unblock site_cart'>
            <span id="Cardebug"></span>
            <span id="theResult" class="the_result">加入購物車中...</span>
            <div class="cart_box cart cart_1" href="#">
                <span class="price"><span class="value">0</span></span>
                <span class="number">(<a href="https://ecssl.pchome.com.tw/sys/cflow/?m=shopcar">0</a>)</span>
                <span class="check"><a href="https://ecssl.pchome.com.tw/sys/cflow/?m=shopcar">結帳&gt;</a></span>
            </div>
        </div>
        <!--購物車 end-->

        <!-- 瀏覽記錄 start-->
        <dl class="site_record unblock">
            <dd class="head"><span>瀏覽紀錄</span><span class="close_box ico close"></span></dd>
            <dd class="body">
                <ul id="ul_list" class="col2f"></ul>
            </dd>
            <dd class="foot unblock">
                <a href="#" target="_BLANK"><span>more&gt;</span></a>
            </dd>
        </dl>
        <!-- 瀏覽記錄 end-->


    </div>

    <!--彈出畫面 start-->
    <div id="PopDiscountContainer" class="site_popDiscount unblock"></div>
    <div id="PopPhoneContainer" class="site_popPhoneNumber unblock"></div>
    <div id="PopMarketingContainer" class="overlay_lightbox site_popLayout site_popGift unblock"></div>
    <!--彈出畫面 end-->
    <!--分期銀行資料 start-->
    <div id="PopInstallment" class="site_popInstallment unblock">
        <dl>
            <dt>接受{0}家銀行線上分期付款</dt>
            <dd>{1}</dd>
            <dd>※除不盡餘數於第一期收取</dd>
        </dl>
        <a href="javascript:window.close()">△關視窗</a>
    </div>
    <!--分期銀行資料 end-->
</div>
<form>
<input type="hidden" name="MyEvent" id="MyEvent" >
<input type="hidden" name="inventory" id="inventory" value="0"></form>
</body>
</html>

In [13]:
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


try{jsonp_button([{"Seq":13666714,"Id":"DRAA0C-A90067G2U-000","Price":{"M":2999,"P":2699},"Qty":"10","ButtonType":"ForSale","SaleStatus":1}]);}catch(e){if(window.console){console.log(e);}}

In [ ]:
# -*- 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()

In [14]:
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


   Hello World This is link1 This is link2 \  

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


<a class="link" href="#">This is link1</a>
<a class="link" href="# link2">This is link2</a>

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


[<h1 id="title">Hello World</h1>]
<h1 id="title">Hello World</h1>
Hello World

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


[<a class="link" href="#">This is link1</a>, <a class="link" href="# link2">This is link2</a>]
<a class="link" href="#">This is link1</a>
This is link1

In [26]:
for link in soup.select('.link'):
    print link.text


This is link1
This is link2

In [32]:
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']


[<a abc="456" class="link" href="#" qoo="123"> </a>]
<a abc="456" class="link" href="#" qoo="123"> </a>
#
[u'link']
123
456

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


#
# link2

In [42]:
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()


•
抗癌針劑出貨 法人看好東洋


(2015/09/11 中央社) 
 
•
晟德:公司負責人遭假扣押一事,對公司財務業務並無影響


(2015/09/09 Moneydj理財網) 
 
•
《台北股市》盤中焦點股:東洋、利勤、國光生、裕民、華亞科


(2015/09/09 時報資訊) 
 
•
東洋8月營收 31個月新高


(2015/09/09 中央社) 
 
•
個股:東洋(4105)經台北地院裁定獲准對董事林榮錦進行假扣押強制執行


(2015/09/09 財訊快報) 
 
•
晟德董座林榮錦聲明:絕無檢察官所指之犯意與犯行,並已向法院提出無罪之答辯


(2015/09/09 Moneydj理財網) 
 
•
東洋:經台北地院裁定獲准對董事林榮錦在債權金額約3.63億範圍內進行假扣押強制執行


(2015/09/09 Moneydj理財網) 
 
•
【公告】台灣東洋經台北地院裁定獲准對董事林榮錦進行假扣押強制執行


(2015/09/08 中央社) 
 
•
【公告】台灣東洋 2015年8月合併營收3.62億元 年增58.87%


(2015/09/08 中央社) 
 
•
台灣東洋8月營收3.62億元年增58.87% 1— 8月達20.28億元


(2015/09/08 鉅亨網)
•
抗癌針劑出貨 法人看好東洋
(2015/09/11 中央社)
•
晟德:公司負責人遭假扣押一事,對公司財務業務並無影響
(2015/09/09 Moneydj理財網)
•
《台北股市》盤中焦點股:東洋、利勤、國光生、裕民、華亞科
(2015/09/09 時報資訊)
•
東洋8月營收 31個月新高
(2015/09/09 中央社)
•
個股:東洋(4105)經台北地院裁定獲准對董事林榮錦進行假扣押強制執行
(2015/09/09 財訊快報)
•
晟德董座林榮錦聲明:絕無檢察官所指之犯意與犯行,並已向法院提出無罪之答辯
(2015/09/09 Moneydj理財網)
•
東洋:經台北地院裁定獲准對董事林榮錦在債權金額約3.63億範圍內進行假扣押強制執行
(2015/09/09 Moneydj理財網)
•
【公告】台灣東洋經台北地院裁定獲准對董事林榮錦進行假扣押強制執行
(2015/09/08 中央社)
•
【公告】台灣東洋 2015年8月合併營收3.62億元 年增58.87%
(2015/09/08 中央社)
•
台灣東洋8月營收3.62億元年增58.87% 1— 8月達20.28億元
(2015/09/08 鉅亨網)

In [43]:
# -*- 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()


2699

In [44]:
import bs4
print dir(bs4)


['BeautifulSoup', 'BeautifulStoneSoup', 'CData', 'Comment', 'DEFAULT_OUTPUT_ENCODING', 'Declaration', 'Doctype', 'FeatureNotFound', 'NavigableString', 'PageElement', 'ParserRejectedMarkup', 'ProcessingInstruction', 'ResultSet', 'SoupStrainer', 'StopParsing', 'Tag', 'UnicodeDammit', '__all__', '__author__', '__builtins__', '__copyright__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__version__', '_s', '_soup', 'builder', 'builder_registry', 'dammit', 'element', 'os', 're', 'syntax_error', 'warnings']

In [45]:
from bs4 import BeautifulSoup 
print dir(BeautifulSoup)


['ASCII_SPACES', 'DEFAULT_BUILDER_FEATURES', 'HTML_FORMATTERS', 'ROOT_TAG_NAME', 'XML_FORMATTERS', '__call__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_all_strings', '_attr_value_as_string', '_attribute_checker', '_feed', '_find_all', '_find_one', '_formatter_for_name', '_is_xml', '_lastRecursiveChild', '_last_descendant', '_popToTag', '_select_debug', '_selector_combinators', '_should_pretty_print', '_tag_name_matches_and', 'append', 'attribselect_re', 'childGenerator', 'children', 'clear', 'decode', 'decode_contents', 'decompose', 'descendants', 'encode', 'encode_contents', 'endData', 'extract', 'fetchNextSiblings', 'fetchParents', 'fetchPrevious', 'fetchPreviousSiblings', 'find', 'findAll', 'findAllNext', 'findAllPrevious', 'findChild', 'findChildren', 'findNext', 'findNextSibling', 'findNextSiblings', 'findParent', 'findParents', 'findPrevious', 'findPreviousSibling', 'findPreviousSiblings', 'find_all', 'find_all_next', 'find_all_previous', 'find_next', 'find_next_sibling', 'find_next_siblings', 'find_parent', 'find_parents', 'find_previous', 'find_previous_sibling', 'find_previous_siblings', 'format_string', 'get', 'getText', 'get_text', 'handle_data', 'handle_endtag', 'handle_starttag', 'has_attr', 'has_key', 'index', 'insert', 'insert_after', 'insert_before', 'isSelfClosing', 'is_empty_element', 'new_string', 'new_tag', 'next', 'nextGenerator', 'nextSibling', 'nextSiblingGenerator', 'next_elements', 'next_siblings', 'object_was_parsed', 'parentGenerator', 'parents', 'parserClass', 'popTag', 'prettify', 'previous', 'previousGenerator', 'previousSibling', 'previousSiblingGenerator', 'previous_elements', 'previous_siblings', 'pushTag', 'recursiveChildGenerator', 'renderContents', 'replaceWith', 'replaceWithChildren', 'replace_with', 'replace_with_children', 'reset', 'select', 'setup', 'string', 'strings', 'stripped_strings', 'tag_name_re', 'text', 'unwrap', 'wrap']

In [49]:
import bs4
doup = bs4.BeautifulSoup(res.text)
#print doup