(11).scrapy依賴的模塊Twisted
阿新 • • 發佈:2018-07-03
acc 裝飾 port domain erro pad 三次 repl 得到
#!/usr/bin/env python # -*- coding:utf-8 -*- # author:love_cat from twisted.internet import reactor # 事件循環(終止條件,所有的socket都已經移除) from twisted.internet import defer # defer.Deferred 特殊的socket對象(不發請求,手動移除) from twisted.web.client import getPage # 用於創建socket對象(下載完成,自動從事件循環中移除) # 1. 利用getPage創建socket # 2. 將socket添加到事件循環 # 3. 開始事件循環(內部發送請求,並接受響應;當所有的socket完成後,終止事件循環) def response(content): print(content.decode(‘utf-8‘)) @defer.inlineCallbacks def task(): url = ‘http://www.bilibili.com‘ d = getPage(url.encode(‘utf-8‘)) # 加上裝飾器,得到特殊的socket對象。不發請求,只待在事件循環裏面,用於讓事件循環一直持續,直到我們手動移除 d.addCallback(response) yield d task() reactor.run() # 程序的輸出結果如下 ‘‘‘ <!DOCTYPE html><html lang="zh-Hans"><head><meta charset="utf-8"><title>嗶哩嗶哩 (゜-゜)つロ 幹杯~-bilibili</title><meta name="description" content="bilibili是國內知名的視頻彈幕網站,這裏有最及時的動漫新番,最棒的ACG氛圍,最有創意的Up主。大家可以在這裏找到許多歡樂。"><meta name="keywords" content="B站,彈幕,字幕,AMV,MAD,MTV,ANIME,動漫,動漫音樂,遊戲,遊戲解說,ACG,galgame,動畫,番組,新番,初音,洛天依,vocaloid"><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="spm_prefix" content="333.334"><meta name="baidu-site-verification" content="gbRdPloQBZ"><meta name="360-site-verification" content="6057b3e352a63d37c14dfc82e2ccb288"><meta name="shenma-site-verification" content="a24cb5f89c4c9cb6d35c24236f4bf36d_1527561745"><meta name="google-site-verification" content="P_nC9t8BcWeyX8lXsTAUIAeHKrFuOYQ_uuCDC9mavwg"><link rel="dns-prefetch" href="//s1.hdslb.com"><link rel="dns-prefetch" href="//i0.hdslb.com"><link rel="dns-prefetch" href="//i1.hdslb.com"><link rel="dns-prefetch" href="//i2.hdslb.com"><link rel="dns-prefetch" href="//static.hdslb.com"><link rel="shortcut icon" href="//static.hdslb.com/images/favicon.ico"><link rel="search" type="application/opensearchdescription+xml" href="//static.hdslb.com/opensearch.xml" title="嗶哩嗶哩"><script type="text/javascript" src="//static.hdslb.com/js/jquery.min.js"></script><script type="text/javascript" src="//s1.hdslb.com/bfs/cm/st/bundle.js" crossorigin></script><script type="text/javascript">(function () { var ua = window.navigator.userAgent, agents = [‘Android‘, ‘iPhone‘, ‘SymbianOS‘, ‘Windows Phone‘, ‘iPod‘], isPC = true; for (var i = 0, len = agents.length; i < len; i++) { if (ua.indexOf(agents[i]) > 0) { isPC = false; break; } } if (!isPC) { var href = window.location.href.replace(‘www‘, ‘m‘); window.location.href = href; } })();</script><script type="text/javascript">window.spmReportData = {} window.reportConfig = { sample: 1, scrollTracker: true, msgObjects: ‘spmReportData‘, errorTracker: true }</script><link rel="prefetch" as="script" href="//static.hdslb.com/js/video.min.js"><link rel="stylesheet" href="//s1.hdslb.com/bfs/static/jinkela/home/css/home.1.ddbe2d8c7eac32c8eda17a6419def24ac66ca5c6.css"></head><body><div id="home-app"></div><div id="app" data-server-rendered="true"><div class="bili-header-m report-wrap-module"><div class="nav-menu"><div class="blur-bg"></div><div class="nav-mask"></div><div class="bili-wrapper clearfix"><div class="nav-con fl"><ul><li report-id="playpage_main" class="nav-item home"><a href="//www.bilibili.com" title="主站" class="t"><i class="bili-icon"></i>主站</a></li><li report-id="playpage_huahua" class="nav-item hbili"><a href="//h.bilibili.com" target="_blank" title="畫友" class="t">畫友</a></li><li report-id="playpage_game" class="nav-item game"><a href="//game.bilibili.com" target="_blank" title="遊戲中心" class="t">遊戲中心</a><!----></li><li report-id="playpage_live" class="nav-item live"><a href="//live.bilibili.com" target="_blank" title="直播" class="t">直播</a><!----></li><li report-id="playpage_buy" class="nav-item buy"><a href="//show.bilibili.com/platform/home.html?msource=pc_web" target="_blank" title="會員購" class="t">會員購</a></li><li report-id="playpage_bml" class="nav-item"><a href="//bml.bilibili.com" target="_blank" title="BML" class="t">BML</a></li><li report-id="playpage_bworld" class="nav-item"><a href="//bw.bilibili.com" target="_blank" title="BWORLD" class="t">BW</a></li><li report-id="playpage_download" class="nav-item mobile"><i class="b-icon b-icon-app"></i><a id="header-mobile-app" href="//app.bilibili.com" target="_blank" title="下載APP" class="t">下載APP</a><!----></li></ul></div><div report-id="playpage_contribution" class="up-load fr"><a href="//member.bilibili.com/v/video/submit.html" target="_blank" class="u-link">投 稿</a><!----></div><!----><!----></div></div><div id="banner_link" class="head-banner report-wrap-module report-scroll-module"><div class="head-content bili-wrapper"><p class="head-title"></p><div class="search"><form class="searchform"><input type="text" autocomplete="off" accesskey="s" x-webkit-speech x-webkit-grammar="builtin:translate" placeholder="" value="" class="search-keyword"><button type="submit" class="search-submit"></button></form><!----><!----><a href="//www.bilibili.com/ranking" target="_blank" class="link-ranking"><span>排行榜</span></a></div><a href="//www.bilibili.com" class="head-logo"></a></div><a href="" target="_blank" class="banner-link"></a></div><div class="bili-wrapper"><div id="primary_menu" class="primary-menu report-wrap-module report-scroll-module "><ul class="nav-menu"><li class="home"><a href="//www.bilibili.com"><!----><div class="nav-name">首頁</div></a><ul class="sub-nav"></ul></li><li><a href="//www.bilibili.com/v/douga/"><div class="num-wrap"><span>--</span></div><div class="nav-name">動畫</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/douga/mad/"><span>MAD·AMV</span></a></li><li><a href="//www.bilibili.com/v/douga/mmd/"><span>MMD·3D</span></a></li><li><a href="//www.bilibili.com/v/douga/voice/"><span>短片·手書·配音</span></a></li><li><a href="//www.bilibili.com/v/douga/other/"><span>綜合</span></a></li></ul></li><li><a href="//www.bilibili.com/anime/"><div class="num-wrap"><span>--</span></div><div class="nav-name">番劇</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/anime/serial/"><span>連載動畫</span></a></li><li><a href="//www.bilibili.com/v/anime/finish/"><span>完結動畫</span></a></li><li><a href="//www.bilibili.com/v/anime/information/"><span>資訊</span></a></li><li><a href="//www.bilibili.com/v/anime/offical/"><span>官方延伸</span></a></li><li><a href="//www.bilibili.com/anime/timeline/"><span>新番時間表</span></a></li><li><a href="//www.bilibili.com/anime/index/"><span>番劇索引</span></a></li></ul></li><li><a href="//www.bilibili.com/guochuang/"><div class="num-wrap"><span>--</span></div><div class="nav-name">國創</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/guochuang/chinese/"><span>國產動畫</span></a></li><li><a href="//www.bilibili.com/v/guochuang/original/"><span>國產原創相關</span></a></li><li><a href="//www.bilibili.com/v/guochuang/puppetry/"><span>布袋戲</span></a></li><li><a href="//www.bilibili.com/v/guochuang/information/"><span>資訊</span></a></li><li><a href="//www.bilibili.com/guochuang/timeline/"><span>新番時間表</span></a></li><li><a href="//www.bilibili.com/guochuang/index/"><span>國產動畫索引</span></a></li></ul></li><li><a href="//www.bilibili.com/v/music/"><div class="num-wrap"><span>--</span></div><div class="nav-name">音樂</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/music/original/"><span>原創音樂</span></a></li><li><a href="//www.bilibili.com/v/music/cover/"><span>翻唱</span></a></li><li><a href="//www.bilibili.com/v/music/vocaloid/"><span>VOCALOID·UTAU</span></a></li><li><a href="//www.bilibili.com/v/music/perform/"><span>演奏</span></a></li><li><a href="//www.bilibili.com/v/music/coordinate/"><span>三次元音樂</span></a></li><li><a href="//www.bilibili.com/v/music/oped/"><span>OP/ED/OST</span></a></li><li><a href="//www.bilibili.com/v/music/collection/"><span>音樂選集</span></a></li></ul></li><li><a href="//www.bilibili.com/v/dance/"><div class="num-wrap"><span>--</span></div><div class="nav-name">舞蹈</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/dance/otaku/"><span>宅舞</span></a></li><li><a href="//www.bilibili.com/v/dance/three_d/"><span>三次元舞蹈</span></a></li><li><a href="//www.bilibili.com/v/dance/demo/"><span>舞蹈教程</span></a></li></ul></li><li><a href="//www.bilibili.com/v/game/"><div class="num-wrap"><span>--</span></div><div class="nav-name">遊戲</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/game/stand_alone/"><span>單機遊戲</span></a></li><li><a href="//www.bilibili.com/v/game/esports/"><span>電子競技</span></a></li><li><a href="//www.bilibili.com/v/game/mobile/"><span>手機遊戲</span></a></li><li><a href="//www.bilibili.com/v/game/online/"><span>網絡遊戲</span></a></li><li><a href="//www.bilibili.com/v/game/board/"><span>桌遊棋牌</span></a></li><li><a href="//www.bilibili.com/v/game/gmv/"><span>GMV</span></a></li><li><a href="//www.bilibili.com/v/game/music/"><span>音遊</span></a></li><li><a href="//www.bilibili.com/v/game/mugen/"><span>Mugen</span></a></li></ul></li><li><a href="//www.bilibili.com/v/technology/"><div class="num-wrap"><span>--</span></div><div class="nav-name">科技</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/technology/fun/"><span>趣味科普人文</span></a></li><li><a href="//www.bilibili.com/v/technology/wild/"><span>野生技術協會</span></a></li><li><a href="//www.bilibili.com/v/technology/speech_course/"><span>演講·公開課</span></a></li><li><a href="//www.bilibili.com/v/technology/military/"><span>星海</span></a></li><li><a href="//www.bilibili.com/v/technology/digital/"><span>數碼</span></a></li><li><a href="//www.bilibili.com/v/technology/mechanical/"><span>機械</span></a></li><li><a href="//www.bilibili.com/v/technology/automobile/"><span>汽車</span></a></li></ul></li><li><a href="//www.bilibili.com/v/life/"><div class="num-wrap"><span>--</span></div><div class="nav-name">生活</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/life/funny/"><span>搞笑</span></a></li><li><a href="//www.bilibili.com/v/life/daily/"><span>日常</span></a></li><li><a href="//www.bilibili.com/v/life/food/"><span>美食圈</span></a></li><li><a href="//www.bilibili.com/v/life/animal/"><span>動物圈</span></a></li><li><a href="//www.bilibili.com/v/life/handmake/"><span>手工</span></a></li><li><a href="//www.bilibili.com/v/life/painting/"><span>繪畫</span></a></li><li><a href="//www.bilibili.com/v/life/asmr/"><span>ASMR</span></a></li><li><a href="//www.bilibili.com/v/life/sports/"><span>運動</span></a></li><li><a href="//www.bilibili.com/v/life/other/"><span>其他</span></a></li></ul></li><li><a href="//www.bilibili.com/v/kichiku/"><div class="num-wrap"><span>--</span></div><div class="nav-name">鬼畜</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/kichiku/guide/"><span>鬼畜調教</span></a></li><li><a href="//www.bilibili.com/v/kichiku/mad/"><span>音MAD</span></a></li><li><a href="//www.bilibili.com/v/kichiku/manual_vocaloid/"><span>人力VOCALOID</span></a></li><li><a href="//www.bilibili.com/v/kichiku/course/"><span>教程演示</span></a></li></ul></li><li><a href="//www.bilibili.com/v/fashion/"><div class="num-wrap"><span>--</span></div><div class="nav-name">時尚</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/fashion/makeup/"><span>美妝</span></a></li><li><a href="//www.bilibili.com/v/fashion/clothing/"><span>服飾</span></a></li><li><a href="//www.bilibili.com/v/fashion/aerobics/"><span>健身</span></a></li><li><a href="//www.bilibili.com/v/fashion/information/"><span>資訊</span></a></li></ul></li><li><a href="//www.bilibili.com/v/ad/ad/"><div class="num-wrap"><span>--</span></div><div class="nav-name">廣告</div></a><ul class="sub-nav"><!----></ul></li><li><a href="//www.bilibili.com/v/ent/"><div class="num-wrap"><span>--</span></div><div class="nav-name">娛樂</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/ent/variety/"><span>綜藝</span></a></li><li><a href="//www.bilibili.com/v/ent/star/"><span>明星</span></a></li><li><a href="//www.bilibili.com/v/ent/korea/"><span>Korea相關</span></a></li></ul></li><li><a href="//www.bilibili.com/v/cinephile/"><div class="num-wrap"><span>--</span></div><div class="nav-name">影視</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/v/cinephile/cinecism/"><span>影視雜談</span></a></li><li><a href="//www.bilibili.com/v/cinephile/montage/"><span>影視剪輯</span></a></li><li><a href="//www.bilibili.com/v/cinephile/shortfilm/"><span>短片</span></a></li><li><a href="//www.bilibili.com/v/cinephile/trailer_info/"><span>預告·資訊</span></a></li><li><a href="//www.bilibili.com/v/cinephile/tokusatsu/"><span>特攝</span></a></li></ul></li><li><a href="//www.bilibili.com/cinema/"><div class="num-wrap"><span>--</span></div><div class="nav-name">放映廳</div></a><ul class="sub-nav"><li><a href="//www.bilibili.com/documentary/"><span>紀錄片</span></a></li><li><a href="//www.bilibili.com/movie/"><span>電影</span></a></li><li><a href="//www.bilibili.com/tv/"><span>電視劇</span></a></li></ul></li><li class="side-nav zl"><a href="//www.bilibili.com/read/home" class="side-link"><i class="zhuanlan"></i><span>專欄</span></a></li><li class="side-nav nav-square"><a href="//www.bilibili.com/square" class="side-link"><i class="square"></i><span>廣場</span></a><div class="sub-nav square-wrap"><ul><li><a href="//show.bilibili.com/platform/home.html"><i class="icon-prim icon-vip-buy"></i><span>會員購</span></a></li><li><a href="//activity.bilibili.com"><i class="icon-prim icon-activity"></i><span>活動中心</span></a></li><li><a href="//game.bilibili.com"><i class="icon-prim icon-game"></i><span>遊戲中心</span></a></li><li><a href="//news.bilibili.com"><i class="icon-prim icon-news"></i><span>新聞中心</span></a></li><li><a href="http://h.bilibili.com"><i class="icon-prim icon-hy"></i><span>畫友</span></a></li><li><a href="//www.bilibili.com/mango"><i class="icon-prim icon-mango"></i><span>芒果TV</span></a></li></ul><div class="square-field"></div></div></li><li class="side-nav"><a href="//live.bilibili.com" class="side-link"><i class="live"></i><span>直播</span></a><div class="sub-nav nav-live"><ul><li><a href="//live.bilibili.com/subject"><span>推薦主播</span></a></li><li><a href="//live.bilibili.com/pages/area/ent"><span>生活娛樂</span></a></li><li><a href="//live.bilibili.com/draw"><span>繪畫專區</span></a></li><li><a href="//live.bilibili.com/pages/area/ent"><span>唱見舞見</span></a></li><li><a href="//live.bilibili.com/pages/area/ent"><span>禦宅文化</span></a></li><li><a href="//live.bilibili.com/single"><span>單機聯機</span></a></li><li><a href="//live.bilibili.com/online"><span>網絡遊戲</span></a></li><li><a href="//live.bilibili.com/e-sports"><span>電子競技</span></a></li><li><a href="//live.bilibili.com/mobile-game"><span>手遊直播</span></a></li></ul><div class="live-field fl"><a target="_blank" href="//h.bilibili.com" class="pic"><img src="//s1.hdslb.com/bfs/static/jinkela/home/images/wh2.png" alt="有文畫"></a><a target="_blank" href="//vc.bilibili.com" class="pic"><img src="//s1.hdslb.com/bfs/static/jinkela/home/images/sp2.png" alt="小視頻"></a></div></div></li><li class="side-nav"><a href="//www.bilibili.com/blackroom/" class="side-link"><i class="blackroom"></i><span>小黑屋</span></a></li></ul><div class="gif-menu nav-gif"><a href="" target="_blank" title="" class="random-p"><img src="" alt></a></div></div></div></div><div class="bili-wrapper"><div id="chief_recommend" class="chief-recommend-module report-wrap-module report-scroll-module clearfix"><div class="carousel-box"><div class="load-state"><span class="loading">正在加載...</span><!----><!----></div><div class="carousel-module"><div class="panel"><ul class="pic" style="width:0%;margin-left:--100%;height:;margin-top:;"></ul><ul class="title"></ul><!----></div></div></div><div class="recommend-module clearfix"><!----><div class="groom-module home-card"><a href="/video/av24383566/" target="_blank" title="【ACG大事件】肉番表化,熱血再臨,任天堂就是世界的主宰啊!"><img src="//i2.hdslb.com/bfs/archive/b43bd38af92c6ace7d8fb639250581df99d808c9.jpg@160w_100h.jpg" alt="【ACG大事件】肉番表化,熱血再臨,任天堂就是世界的主宰啊!" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【ACG大事件】肉番表化,熱血再臨,任天堂就是世界的主宰啊!</p><p class="author">up主:小M嗚喵王</p><p class="play">播放:3.6萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24380638/" target="_blank" title="【圈9x絕非言】生如逆旅【高考應援】【Lemon中文填翻】"><img src="//i0.hdslb.com/bfs/archive/4a1d0d3562102e7ba765dd5af0d6668c2fc85ac3.png@160w_100h.png" alt="【圈9x絕非言】生如逆旅【高考應援】【Lemon中文填翻】" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【圈9x絕非言】生如逆旅【高考應援】【Lemon中文填翻】</p><p class="author">up主:WineQ圈9</p><p class="play">播放:3.9萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24318495/" target="_blank" title="【次郎】有球就給贊的清涼一夏!2018夏七月新番導視"><img src="//i2.hdslb.com/bfs/archive/4bcb73269767f7f3b573f65f977851c4e6355c44.jpg@160w_100h.jpg" alt="【次郎】有球就給贊的清涼一夏!2018夏七月新番導視" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【次郎】有球就給贊的清涼一夏!2018夏七月新番導視</p><p class="author">up主:次郎JIRO</p><p class="play">播放:7.6萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24364690/" target="_blank" title="【高考大魔王】一口氣全做對"><img src="//i0.hdslb.com/bfs/archive/b74884a76c6f89aae4f37aacf2541343d6890f1a.png@160w_100h.png" alt="【高考大魔王】一口氣全做對" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【高考大魔王】一口氣全做對</p><p class="author">up主:推背兔の</p><p class="play">播放:9.4萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24320325/" target="_blank" title="【DNF】他的故事"><img src="//i2.hdslb.com/bfs/archive/0ea53531d36eaca6420a0e2ca8bffa294aa9302c.jpg@160w_100h.jpg" alt="【DNF】他的故事" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【DNF】他的故事</p><p class="author">up主:小巨人豬大星</p><p class="play">播放:19.0萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24313640/" target="_blank" title="【起風了】一首為西卡和周淑怡寫的情歌(個人翻唱填詞)。催淚向"><img src="//i2.hdslb.com/bfs/archive/c0e3dc4307220cacec7ded0ba97f724f4c628af7.png@160w_100h.png" alt="【起風了】一首為西卡和周淑怡寫的情歌(個人翻唱填詞)。催淚向" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【起風了】一首為西卡和周淑怡寫的情歌(個人翻唱填詞)。催淚向</p><p class="author">up主:是烏龍院長啊</p><p class="play">播放:8.7萬</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24310866/" target="_blank" title="【初音未來V4C原創】LIME LIGHT【蜂屋ななし@休閑主義】"><img src="//i1.hdslb.com/bfs/archive/e896ae1793e6c701f31ded251da1e22b56f8b4c6.jpg@160w_100h.jpg" alt="【初音未來V4C原創】LIME LIGHT【蜂屋ななし@休閑主義】" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【初音未來V4C原創】LIME LIGHT【蜂屋ななし@休閑主義】</p><p class="author">up主:蜂屋ななし</p><p class="play">播放:3154</p></div></a><div class="watch-later-trigger w-later"></div></div><div class="groom-module home-card"><a href="/video/av24240231/" target="_blank" title="【菌子】激昂壯誌!從今以後,你就是我的人了?(鸞cos)"><img src="//i2.hdslb.com/bfs/archive/52fb8aad69581cfc61ae2d864223890ddbb86db6.jpg@160w_100h.jpg" alt="【菌子】激昂壯誌!從今以後,你就是我的人了?(鸞cos)" width="160" height="100" class="pic"><!----><div class="card-mark"><p class="title">【菌子】激昂壯誌!從今以後,你就是我的人了?(鸞cos)</p><p class="author">up主:淺野菌子</p><p class="play">播放:16.7萬</p></div></a><div class="watch-later-trigger w-later"></div></div><span class="rec-btn prev">昨日</span><span class="rec-btn next">一周</span></div></div><div id="home_popularize" class="popularize-module report-wrap-module report-scroll-module clearfix"><div class="l-con"><div class="headline clearfix"><i class="icon icon_t icon-promote"></i><span class="name">推廣</span></div><div class="storey-box clearfix"><div class="load-state"><span class="loading">正在加載...</span><!----><!----></div></div></div><div class="r-con"><div class="online"><a href="//www.bilibili.com/video/online.html" target="_blank" title="在線觀看:0">在線人數:0</a><em></em><a href="//www.bilibili.com/newlist.html" target="_blank">最新投稿:0</a></div><!----></div></div><!----><div id="special_recommend" class="special-recommend-module report-wrap-module report-scroll-module clearfix"><div class="l-con"><div class="headline clearfix"><i class="icon icon_t icon-special"></i><a href="//www.bilibili.com/list/recommend/1.html" class="name">特別推薦</a></div><div class="storey-box clearfix"><div class="load-state"><span class="loading">正在加載...</span><!----><!----></div></div></div><!----></div></div><!----><!----><!----><!----><!----></div><script>window.__INITIAL_STATE__={"recommendData":[{"aid":"24383566","typename":"綜合","title":"【ACG大事件】肉番表化,熱血再臨,任天堂就是世界的主宰啊!","subtitle":"","play":35936,"review":241,"video_review":725,"favorites":1594,"mid":346059,"author":"小M嗚喵王","create":"2018-06-04 22:26","pic":"http:\u002F\u002Fi2.hdslb.com\u002Fbfs\u002Farchive\u002Fb43bd38af92c6ace7d8fb639250581df99d808c9.jpg","coins":3790,"duration":"15:31","badgepay":false},{"aid":"24380638","typename":"翻唱","title":"【圈9x絕非言】生如逆旅【高考應援】【Lemon中文填翻】","subtitle":"","play":38939,"review":1265,"video_review":1485,"favorites":3484,"mid":3797626,"author":"WineQ圈9","create":"2018-06-04 21:29","pic":"http:\u002F\u002Fi0.hdslb.com\u002Fbfs\u002Farchive\u002F4a1d0d3562102e7ba765dd5af0d6668c2fc85ac3.png","coins":6216,"duration":"6:42","badgepay":false},{"aid":"24318495","typename":"綜合","title":"【次郎】有球就給贊的清涼一夏!2018夏七月新番導視","subtitle":"","play":76295,"review":399,"video_review":1770,"favorites":3507,"mid":10915924,"author":"次郎JIRO","create":"2018-06-03 13:39","pic":"http:\u002F\u002Fi2.hdslb.com\u002Fbfs\u002Farchive\u002F4bcb73269767f7f3b573f65f977851c4e6355c44.jpg","coins":7228,"duration":"15:12","badgepay":false},{"aid":"24364690","typename":"人力VOCALOID","title":"【高考大魔王】一口氣全做對","subtitle":"","play":93847,"review":696,"video_review":634,"favorites":4357,"mid":96070394,"author":"推背兔の","create":"2018-06-04 17:31","pic":"http:\u002F\u002Fi0.hdslb.com\u002Fbfs\u002Farchive\u002Fb74884a76c6f89aae4f37aacf2541343d6890f1a.png","coins":6300,"duration":"2:51","badgepay":false},{"aid":"24320325","typename":"人力VOCALOID","title":"【DNF】他的故事","subtitle":"","play":190380,"review":3550,"video_review":2553,"favorites":10103,"mid":13357338,"author":"小巨人豬大星","create":"2018-06-03 14:27","pic":"http:\u002F\u002Fi2.hdslb.com\u002Fbfs\u002Farchive\u002F0ea53531d36eaca6420a0e2ca8bffa294aa9302c.jpg","coins":32611,"duration":"4:02","badgepay":false},{"aid":"24313640","typename":"翻唱","title":"【起風了】一首為西卡和周淑怡寫的情歌(個人翻唱填詞)。催淚向","subtitle":"","play":86961,"review":1772,"video_review":3880,"favorites":3027,"mid":1692960,"author":"是烏龍院長啊","create":"2018-06-03 11:23","pic":"http:\u002F\u002Fi2.hdslb.com\u002Fbfs\u002Farchive\u002Fc0e3dc4307220cacec7ded0ba97f724f4c628af7.png","coins":11014,"duration":"5:20","badgepay":false},{"aid":"24310866","typename":"V家","title":"【初音未來V4C原創】LIME LIGHT【蜂屋ななし@休閑主義】","subtitle":"","play":3154,"review":149,"video_review":117,"favorites":666,"mid":27444222,"author":"蜂屋ななし","create":"2018-06-03 10:20","pic":"http:\u002F\u002Fi1.hdslb.com\u002Fbfs\u002Farchive\u002Fe896ae1793e6c701f31ded251da1e22b56f8b4c6.jpg","coins":669,"duration":"3:33","badgepay":false},{"aid":"24240231","typename":"宅舞","title":"【菌子】激昂壯誌!從今以後,你就是我的人了?(鸞cos)","subtitle":"","play":167367,"review":566,"video_review":337,"favorites":4288,"mid":8581342,"author":"淺野菌子","create":"2018-06-03 00:00","pic":"http:\u002F\u002Fi2.hdslb.com\u002Fbfs\u002Farchive\u002F52fb8aad69581cfc61ae2d864223890ddbb86db6.jpg","coins":2892,"duration":"4:19","badgepay":false}]};(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());</script><script src="//s1.hdslb.com/bfs/static/jinkela/home/manifest.ddbe2d8c7eac32c8eda17a6419def24ac66ca5c6.js" crossorigin defer></script><script src="//s1.hdslb.com/bfs/static/jinkela/home/vendor.ddbe2d8c7eac32c8eda17a6419def24ac66ca5c6.js" crossorigin defer></script><script src="//s1.hdslb.com/bfs/static/jinkela/home/home.ddbe2d8c7eac32c8eda17a6419def24ac66ca5c6.js" crossorigin defer></script><div class="footer bili-footer report-wrap-module"></div><script type="text/javascript">if(!+"\v1"){ document.body.innerHTML = "<div style=‘background: #00a1d6; text-align: center; padding: 10px 0; color: #fff;‘>為了保護你的賬號安全,bilibili已不支持IE8及以下版本瀏覽器訪問,建議你升級到IE最新版本瀏覽器,或使用Chrome等其他瀏覽器。<\/div>" }</script><script type="text/javascript" charset="utf-8" src="//static.hdslb.com/common/js/footer.js"></script><!-- built files will be auto injected --><script type="text/javascript">//防嵌入 (function(){try{if(parent!=self && (parent.document.domain!=document.domain || (document.referrer && !/^http(s)?:\/\/[.\w-]+\.bilibili\.com\//i.test(document.referrer)))){throw new Error("can‘t be iframed");}}catch(e){window.open(location.href, "_top");}})();</script></body></html> ‘‘‘ @defer.inlineCallbacks def task1(): url = ‘http://www.bilibili.com‘ d = getPage(url.encode(‘utf-8‘)) d.addCallback(response) yield d @defer.inlineCallbacks def task2(): url=‘http://www.baidu.com‘ d = getPage(url.encode(‘utf-8‘)) d.addCallback(response) url = ‘http://www.bilibili.com‘ d = getPage(url.encode(‘utf-8‘)) d.addCallback(response) yield d def response(content): print(content.decode(‘utf-8‘)[0:1000]) # 這裏只取前1000個字符 def run_until_complete(*args,**kwargs): reactor.stop() t1 = task1() t2 = task2() all_task = defer.DeferredList([t1,t2]) all_task.addBoth(run_until_complete) reactor.run() # 程序的輸出結果如下 ‘‘‘ <!DOCTYPE html> <!--STATUS OK--> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta content="always" name="referrer"> <meta name="theme-color" content="#2932e1"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /> <link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg"> <link rel="dns-prefetch" href="//s1.bdstatic.com"/> <lin <!DOCTYPE html><html lang="zh-Hans"><head><meta charset="utf-8"><title>嗶哩嗶哩 (゜-゜)つロ 幹杯~-bilibili</title><meta name="description" content="bilibili是國內知名的視頻彈幕網站,這裏有最及時的動漫新番,最棒的ACG氛圍,最有創意的Up主。大家可以在這裏找到許多歡樂。"><meta name="keywords" content="B站,彈幕,字幕,AMV,MAD,MTV,ANIME,動漫,動漫音樂,遊戲,遊戲解說,ACG,galgame,動畫,番組,新番,初音,洛天依,vocaloid"><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="spm_prefix" content="333.334"><meta name="baidu-site-verification" content="gbRdPloQBZ"><meta name="360-site-verification" content="6057b3e352a63d37c14dfc82e2ccb288"><meta name="shenma-site-verification" content="a24cb5f89c4c9cb6d35c24236f4bf36d_1527561745"><meta name="google-site-verification" content="P_nC9t8BcWeyX8lXsTAUIAeHKrFuOYQ_uuCDC9mavwg"><link rel="dns-prefetch" href="//s1.hdslb.com"><link rel="dns-prefetch" href="//i0.hdslb.com"><link rel="dns-prefetch" href="//i1.hdslb.com"><link rel="dns-prefetch" href="//i2.hdslb.com"><link rel="dns-prefetch" href="//static.h <!DOCTYPE html><html lang="zh-Hans"><head><meta charset="utf-8"><title>嗶哩嗶哩 (゜-゜)つロ 幹杯~-bilibili</title><meta name="description" content="bilibili是國內知名的視頻彈幕網站,這裏有最及時的動漫新番,最棒的ACG氛圍,最有創意的Up主。大家可以在這裏找到許多歡樂。"><meta name="keywords" content="B站,彈幕,字幕,AMV,MAD,MTV,ANIME,動漫,動漫音樂,遊戲,遊戲解說,ACG,galgame,動畫,番組,新番,初音,洛天依,vocaloid"><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="spm_prefix" content="333.334"><meta name="baidu-site-verification" content="gbRdPloQBZ"><meta name="360-site-verification" content="6057b3e352a63d37c14dfc82e2ccb288"><meta name="shenma-site-verification" content="a24cb5f89c4c9cb6d35c24236f4bf36d_1527561745"><meta name="google-site-verification" content="P_nC9t8BcWeyX8lXsTAUIAeHKrFuOYQ_uuCDC9mavwg"><link rel="dns-prefetch" href="//s1.hdslb.com"><link rel="dns-prefetch" href="//i0.hdslb.com"><link rel="dns-prefetch" href="//i1.hdslb.com"><link rel="dns-prefetch" href="//i2.hdslb.com"><link rel="dns-prefetch" href="//static.h ‘‘‘
#!/usr/bin/env python # -*- coding:utf-8 -*- # author:love_cat from twisted.internet import reactor,task def hello(name): print(‘hello‘, name) task1 = task.LoopingCall(hello, ‘satori‘) # 每隔十秒鐘運行一次 task1.start(10) reactor.callWhenRunning(hello, ‘mmp‘) # 當循環開始時,運行 reactor.callLater(3, hello, ‘mmppp‘) # 循環開始後三秒,運行 reactor.run() ‘‘‘ hello satori hello mmp hello mmppp hello satori hello satori hello satori hello satori hello satori ..... ..... ..... ‘‘‘
(11).scrapy依賴的模塊Twisted