[英]scrapy extract source url from javascript
我正在嘗試從javascript中提取數據。 js看起來像-
<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>
我需要http://cdn1.gomoviesgo.com/movies/1230451279-cover-Wonder-Woman.jpg
圖片網址和"http:\\/\\/stream.gomo.to\\/home\\/movies\\/tt0451279.mp4"
來源網址"http:\\/\\/stream.gomo.to\\/home\\/movies\\/tt0451279.mp4"
請指導。
您無法使用html解析器解析js,但是可以使用正則表達式。
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('\\', '')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.