我有一个PHP / jQuery scraper函数,它主要查找网页内容。
一种方法可以查找视频。在测试youtube视频页面时,视频会被抓取并显示得很好。源代码看起来像:
<embed width="320" height="240" bgcolor="#000000" allowfullscreen="true" allowscriptaccess="always" flashvars="account_playback_token=&ptk=KrebsCOHO%252Buser&enablecsi=1&iv_close_button=0&mpvid=AAS2NjXQtb70zY15&fexp=912208%2C914092%2C906423%2C901604&hl=en_GB&autohide=2&csi_page_type=watch5ad&keywords=Company+of+Heroes%2CCompany+of+Heroes+2%2CCOH+2%2CCOH%2CCOHO%2CCompany+of+Heroes+Online%2CvCOH%2CCommander%2CDefensive+Doctrine%2CAirborne+Doctrine%2CInfantry+Doctrine%2CBlitzkrieg+Doctrine%2CTerror+Doctrine%2CArmor+Doctrine%2CGenHansKrebs%2CKrebsCOHO%2CCompany+of+Heroes+Replays%2CCompany+of+Heroes+Casts%2CCompany+of+Heroes+Brits%2CCompany+of+Heroes+British%2CPanzer+Elite%2CTales+of+Valor%2COpposing+Fronts%2CCOH+Strategy%2CCompany+of+Heroes+Cheats%2CCompany+of+Heroes+Hacks&cr=GB&cc3_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fsubtitles3_module-vflNKUm_s.swf&host_language=en&iv3_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fiv3_module-vflVIYXve.swf&no_get_video_log=1&fmt_list=46%2F1920x1080%2F99%2F0%2F0%2C45%2F1280x720%2F99%2F0%2F0%2C22%2F1280x720%2F9%2F0%2F115%2C44%2F854x480%2F99%2F0%2F0%2C35%2F854x480%2F9%2F0%2F115%2C43%2F640x360%2F99%2F0%2F0%2C34%2F640x360%2F9%2F0%2F115%2C18%2F640x360%2F9%2F0%2F115%2C5%2F320x240%2F7%2F0%2F0&iv_storage_server=http%3A%2F%2Fwww.youtube.com%2Fannotations%2F&targeting_video_doc_id=&trueview=True&theme=tlb&ad_preroll=1&tk=A6fmSiw2bPJ1To1EkQ_GEhN5IQb7NH3SA2Lr7AmnDtyq0YRIw5HQFw%3D%3D&iv_load_policy=1&cc_font=Arial+Unicode+MS%2C+arial%2C+verdana%2C+_sans&watch_xlb=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fxlb%2Fwatch%2Fstrings-en_GB-vflXhsWkH.xlb&ad_channel_code_instream=afv_instream%2CVertical_Instream_8%2CVertical_Instream_41%2CVertical_Instream_933%2CVidVert8%2CVidVert41%2CVidVert933%2CVertical_8%2CVertical_41%2CVertical_933%2Cafv_instream_gb%2Cyt_mpvid_AAS2NjXQtb70zY15%2Cyt_cid_1640983%2Civp%2Cytexp_912208.914092.906423.901604%2Cytps_default%2Cytel_detailpage&sdetail=f%3Ag-u%2C&cafe_experiment_id=&timestamp=1326243854&cc_asr=1&ad_host=ca-host-pub-6901191551304350&ad_eurl=http%3A%2F%2Fwww.youtube.com%2Fvideo%2F0LzC0V_6TfI&showpopout=1&url_encoded_fmt_stream_map=url%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v2.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D46%2526ip%253D95.0.0.0%2526signature%253DBB3EA0AD473B59EC8EE739170DFC4252629C04F1.A698AF6CCB326B05C6F31A687CB5C47003607517%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dhd1080%26fallback_host%3Dtc.v2.cache4.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D46%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v22.lscache1.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D45%2526ip%253D95.0.0.0%2526signature%253D9CA9C6F49F04CB131E4D3B9CFD12846CFA9E0C20.20C107ED1D2902332117EE528BB48DCB8A24D7CB%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dhd720%26fallback_host%3Dtc.v22.cache1.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D45%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v1.lscache1.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D22%2526ip%253D95.0.0.0%2526signature%253DB20BCC27B8113F47F66278E4208FE39BD53963C2.053298B3B43263F014DE8F65BE964D3815CB7683%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dhd720%26fallback_host%3Dtc.v1.cache1.c.youtube.com%26type%3Dvideo%252Fmp4%253B%2Bcodecs%253D%2522avc1.64001F%252C%2Bmp4a.40.2%2522%26itag%3D22%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v10.lscache8.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D44%2526ip%253D95.0.0.0%2526signature%253D716B089CA9DFDB211533C46127FF2183118B8113.881E822D36F6CF39699C3BFAE2AFCF97B4BB9586%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dlarge%26fallback_host%3Dtc.v10.cache8.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D44%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v14.lscache5.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526algorithm%253Dthrottle-factor%2526itag%253D35%2526ip%253D95.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253D724A616F7861BC4BFF321FAC98F78FEF9F50183D.540D2E9D4E1772AE72CE68124A6BDCA3844E37FA%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dlarge%26fallback_host%3Dtc.v14.cache5.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D35%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v9.lscache2.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D43%2526ip%253D95.0.0.0%2526signature%253D5690ED3BF298418A63A1FC3C88C958A68584195B.457E8F33852B796BECA5640EF06DC20DDE82154C%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dmedium%26fallback_host%3Dtc.v9.cache2.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26itag%3D43%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v6.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526algorithm%253Dthrottle-factor%2526itag%253D34%2526ip%253D95.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253D893DB716EDFB212C142092E4CDBCC0411D5F739F.ABE5CCCB87A14F189EF7CC5B09E5E9155FA42A4C%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dmedium%26fallback_host%3Dtc.v6.cache4.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D34%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v5.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Cratebypass%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526itag%253D18%2526ip%253D95.0.0.0%2526signature%253D961584FFF0C062FAD18B1D50B608148227664DB6.0BE5C5579A29A79168BBFD3356A60CA015603F10%2526sver%253D3%2526ratebypass%253Dyes%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dmedium%26fallback_host%3Dtc.v5.cache4.c.youtube.com%26type%3Dvideo%252Fmp4%253B%2Bcodecs%253D%2522avc1.42001E%252C%2Bmp4a.40.2%2522%26itag%3D18%2Curl%3Dhttp%253A%252F%252Fo-o.preferred.lhr14s15.v21.lscache4.c.youtube.com%252Fvideoplayback%253Fsparams%253Did%25252Cexpire%25252Cip%25252Cipbits%25252Citag%25252Csource%25252Calgorithm%25252Cburst%25252Cfactor%25252Ccp%2526fexp%253D912208%25252C914092%25252C906423%25252C901604%2526algorithm%253Dthrottle-factor%2526itag%253D5%2526ip%253D95.0.0.0%2526burst%253D40%2526sver%253D3%2526signature%253DA9B71D32C230E1F299E367D90AFA645A5D5E80A0.7E100FAA814386C7560B9657AA6932F2D8983458%2526source%253Dyoutube%2526expire%253D1326268838%2526key%253Dyt1%2526ipbits%253D8%2526factor%253D1.25%2526cp%253DU0hRS1JRVl9IUkNOMV9KS1pJOnVjQzhtUzNZVjVv%2526id%253Dd0bcc2d15ffa4df2%26quality%3Dsmall%26fallback_host%3Dtc.v21.cache4.c.youtube.com%26type%3Dvideo%252Fx-flv%26itag%3D5&tmi=1&iv_logging_level=3&ad_flags=0&endscreen_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fendscreen-vfl6o3XZn.swf&cid=1640983&referrer=None&afv_instream_max=20000&ad_logging_flag=1&t=vjVQa1PpcFPtL2KNy9BlI1YWfqrxIuH0Q7IxA2lS4fY%3D&sffb=True&ttsurl=http%3A%2F%2Fwww.youtube.com%2Fapi%2Ftimedtext%3Fsparams%3Dasr_langs%252Ccaps%252Cexpire%252Cv%26asr_langs%3Den%252Cko%252Cja%26caps%3Dasr%26expire%3D1326268800%26key%3Dyttt1%26signature%3D08601E0AFAF4E565C284D451574665CE892A187A.C3A7BCC212D929F08BA9FB37BA1FA706CE8B408B%26hl%3Den-GB&aftv=True&creator=KrebsCOHO&allow_embed=1&ad_host_tier=2902314&rvs=view_count%3D1%252C978%26author%3DKrebsCOHO%26length_seconds%3D2153%26id%3D51if2_4DyoY%26title%3DCompany%2Bof%2BHeroes%2B%252395%2B-%2BGuess%2BWho%2527s%2BBack%2Cview_count%3D1%252C287%26author%3DKrebsCOHO%26length_seconds%3D2128%26id%3DnpOGF24Xun0%26title%3DBattlefield%2B3%2B%25239%2B-%2BThe%2BAmazing%2BBack%2Bto%2BKarkand%2Cview_count%3D2%252C386%26author%3DKrebsCOHO%26length_seconds%3D2913%26id%3Dc91SxbW5RTI%26title%3D%255BCOH%255D%2B%252382%2B-%2BOne%2BMove%2Bto%2BChange%2Bit%2BAll%2Cview_count%3D1%252C337%26author%3Dfrewd100%26length_seconds%3D1555%26id%3DsgxLZTsoZEk%26title%3DCompany%2Bof%2BHeroes%2B3v3%2BOnline%2BBattle%2BRefinery%2B%25281%252F2%2529%2Cview_count%3D3%252C077%26author%3DKrebsCOHO%26length_seconds%3D3400%26id%3D5fHOapLYenQ%26title%3DCompany%2Bof%2BHeroes%2B%252397%2B-%2BEurope%2BIn%2BRuins%2BShowcase%2Cview_count%3D27%252C804%26author%3DEvolvSports%26length_seconds%3D351%26id%3DP4y5fdDZH60%26title%3DChris%2BSharma%2Band%2BMatt%2BSegal%2Bon%2Bthe%2BShaman%2Cview_count%3D2%252C037%26author%3DKrebsCOHO%26length_seconds%3D2569%26id%3DolWg5hYRv0o%26title%3DCompany%2Bof%2BHeroes%2B%252393%2B-%2BValiant%2BSacrifices%2Cview_count%3D255%252C178%26author%3DTheIllustrationArt%26length_seconds%3D180%26id%3DbN1_h_eGitE%26title%3DThe%2BTale%2Bof%2Bthe%2BThree%2BBrothers%2B%2528HD%2529%2Cview_count%3D4%252C312%26author%3DKrebsCOHO%26length_seconds%3D2418%26id%3DG1Isd6SM8aM%26title%3D%255BCOH%255D%2B%252374%2B-%2BLevel%2B20%2BWehrmacht%2Cview_count%3D7%252C734%26author%3DVorbeugungshaft%26length_seconds%3D292%26id%3DEO7NIzsBf44%26title%3DLeger%2Bdes%2BHeils%2B-%2BDer%2BGott%252C%2Bder%2BEisen%2Bwachsen%2Blie%25C3%259F%2Cview_count%3D153%252C325%26author%3DSarahFan0503%26length_seconds%3D338%26id%3DAnUVqu4CYus%26title%3DSarah%2BConnor%2B-%2B%2522Christmas%2BIn%2BMy%2BHeart%2522%2BLIVE%2B%2540%2BThe%2BChristmas%2BSpecial%2B2005%2Cview_count%3D23%252C660%26author%3DTriple6Games%26length_seconds%3D428%26id%3DEPUYh57VlH8%26title%3DTropico%2B4-PC%2BGameplay%2BHD%2BMaxed%2BOut&vq=auto&iv_enabled_features=TCS&sendtmp=1&ad3_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fad3-vfly6I_ZM.swf&gut_tag=%2F4061%2Fytunknown%2Fmain&ptchn=KrebsCOHO&as_launched_in_country=1&length_seconds=2779&feature=g-u&enablejsapi=1&plid=AAS2NjXP5DaZ4rS5&iv_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fiv_module-vflBrKDBK.swf&afv=True&ad_video_pub_id=ca-pub-6219811747049371&ad_slots=0&watermark=%2Chttp%3A%2F%2Fs.ytimg.com%2Fyt%2Fimg%2Fwatermark%2Fyoutube_watermark-vflHX6b6E.png%2Chttp%3A%2F%2Fs.ytimg.com%2Fyt%2Fimg%2Fwatermark%2Fyoutube_hd_watermark-vflAzLcD6.png&supersizefeatured=1&oid=oyMOP28xy70&cc_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fsubtitle_module-vfld45BNe.swf&ad_channel_code_overlay=invideo_overlay_480x70_cat20%2Cafv_overlay%2CVertical_Overlay_8%2CVertical_Overlay_41%2CVertical_Overlay_933%2CVidVert8%2CVidVert41%2CVidVert933%2CVertical_8%2CVertical_41%2CVertical_933%2Cyt_mpvid_AAS2NjXQtb70zY15%2Cyt_cid_1640983%2Civp%2Cytexp_912208.914092.906423.901604%2Cytps_default%2Cytel_detailpage&pyv_in_related_cafe_experiment_id=&video_id=0LzC0V_6TfI&sk=KGM0UWVabLqnTDH6CGaGWIPrk8jgepgiC" id="movie_player" src="http://s.ytimg.com/yt/swfbin/watch_as3-vfl7SkMGe.swf" type="application/x-shockwave-flash">
我想知道的是,如何阻止此视频自动播放?我已尝试过各种方法在autoplay=0
之后添加src
,但没有运气。
有没有人对我正在使用的方法有经验?它在技术上是否可行?
由于
答案 0 :(得分:2)
你的内容过于复杂,你应该使用一点正则表达式获取 youtube视频ID :
if(preg_match('/(?<=video_id=).*?(?=&|")/',$str,$matches)){
$video_id = $matches[0];
}
然后用它来创建真正的嵌入代码:
$youtube = '<iframe width="853" height="480" src="http://www.youtube.com/embed/'.$video_id.'?hd=1" frameborder="0" allowfullscreen></iframe>'
然后它永远不会自动播放
答案 1 :(得分:-1)
尝试将以下内容添加到URL变量中:
&安培;自动播放= 0