2017-09-10 8 views
0

私はJavaScriptからデータを抽出しようとしています。私はhttp://cdn1.gomoviesgo.com/movies/1230451279-cover-Wonder-Woman.jpgある画像のURLと"http:\/\/stream.gomo.to\/home\/movies\/tt0451279.mp4"治療の抽出元のURLをjavascriptから

が案内してくださいあるソースURLが必要

<script type="text/javaScript"> 
var playerInstance = jwplayer("player"); 
playerInstance.setup({ 
    image: "http://cdn1.gomoviesgo.com/movies/1230451279-cover-Wonder-Woman.jpg", 
    sources: JSON.parse('[{"file":"http:\/\/stream.gomo.to\/home\/movies\/tt0451279.mp4","label":"720<sup>HD<\/sup>"}]'), 
    width: "100%" 
}); 
</script> 

- JSは次のようになります。

+0

問題は何ですか? – Siphalor

+0

どのようにこれらのデータを取得できますか。コードを実装できません。 –

+0

あなたのスクラップはPythonでありますか?あなたはあなたのスクレーパーのプレーンテキストファイルとして 'javascript.js'を扱っていますか? –

答えて

0

jsをhtmlパーサーで解析することはできませんが、正規表現を使用することはできます。

image = re.search('image:\s*"(.*?)",', data).group(1) 
file = re.search('"file":"(.*?)",', data).group(1).replace('\\', '') 

それとも、ビルトインreメソッドを使用することができます。

image = response.css('script::text').re('image:\s*"(.*?)",')[0] 
file = response.css('script::text').re('"file":"(.*?)",')[0].replace('\\', '')