页面代码:

< div class="myplayer" >

< div class="m1938" >

< script type="text/javascript" >var player_data={"flag":"play","encrypt":0,"trysee":0,"points":0,"link":"\/index.php\/vod\/play\/id\/9221\/sid\/1\/nid\/1.html","link_next":"","link_pre":"","url":"https:\/\/lbbf9.com\/20200325\/WX8h2pjI\/index.m3u8","url_next":"","from":"lbm3u8","server":"no","note":""}< /script > < script type="text/javascript" src="/static/js/playerconfig.js?t=20200913" >< /script >< script type="text/javascript" src="/static/js/player.js?t=20200913" >< /script >

< style >.MacPlayer{background: #000000;font-size:14px;color:#F6F6F6;margin:0px;padding:0px;position:relative;overflow:hidden;width:100%;height:100%;min-height:100px;}.MacPlayer table{width:100%;height:100%;}.MacPlayer #playleft{position:inherit;!important;width:100%;height:100%;}< /style >

< div class="MacPlayer" >< iframe id="buffer" src="" frameborder="0" scrolling="no" width="100%" height="100%" style="position: absolute; z-index: 99998; display: none;" >< /iframe >< iframe id="install" src="" frameborder="0" scrolling="no" width="100%" height="100%" style="position:absolute;z-index:99998;display:none;" >< /iframe >

< table border="0" cellpadding="0" cellspacing="0" >

< tbody >

< tr >

< td id="playleft" valign="top" style="" >< iframe width="100%" height="100%" src="/static/player/dplayer.html" frameborder="0" allowfullscreen="true" border="0" marginwidth="0" marginheight="0" scrolling="no" >< /iframe >< /td >

< /tr >

< /tbody >

< /table >

< /div >

< script src="/static/player/lbm3u8.js?v=0.5806522403562584" >< /script >< /div >

< /div >

< div class="myplayer" >

< div class="m1938" >

< script type="text/javascript" >var player_data={"flag":"play","encrypt":0,"trysee":0,"points":0,"link":"\/index.php\/vod\/play\/id\/9221\/sid\/1\/nid\/1.html","link_next":"","link_pre":"","url":"https:\/\/lbbf9.com\/20200325\/WX8h2pjI\/index.m3u8","url_next":"","from":"lbm3u8","server":"no","note":""}< /script > < script type="text/javascript" src="/static/js/playerconfig.js?t=20200913" >< /script >< script type="text/javascript" src="/static/js/player.js?t=20200913" >< /script >

< style >.MacPlayer{background: #000000;font-size:14px;color:#F6F6F6;margin:0px;padding:0px;position:relative;overflow:hidden;width:100%;height:100%;min-height:100px;}.MacPlayer table{width:100%;height:100%;}.MacPlayer #playleft{position:inherit;!important;width:100%;height:100%;}< /style >

< div class="MacPlayer" >< iframe id="buffer" src="" frameborder="0" scrolling="no" width="100%" height="100%" style="position: absolute; z-index: 99998; display: none;" >< /iframe >< iframe id="install" src="" frameborder="0" scrolling="no" width="100%" height="100%" style="position:absolute;z-index:99998;display:none;" >< /iframe >

< table border="0" cellpadding="0" cellspacing="0" >

< tbody >

< tr >

< td id="playleft" valign="top" style="" >< iframe width="100%" height="100%" src="/static/player/dplayer.html" frameborder="0" allowfullscreen="true" border="0" marginwidth="0" marginheight="0" scrolling="no" >< /iframe >< /td >

< /tr >

< /tbody >

< /table >

< /div >

< script src="/static/player/lbm3u8.js?v=0.5806522403562584" >< /script >< /div >

< /div >

Python代码:

from bs4 import BeautifulSoup as bs

import re

import json

import requests

def get_m3u8_link(url):

# 直接正则匹配

print('_' * 70)

print('[A] 解析播放地址......')

html_doc = get_url_source_code(url)

bs = BeautifulSoup(html_doc, "html.parser")

pattern = re.compile(r"var cms_player = {(.*?);$", re.MULTILINE | re.DOTALL)

surls = bs.find('script', text=pattern)

js_string = str(surls.text).replace('var cms_player = ', '').replace(';', '')

json_data = json.loads(js_string)

m3u8_link = json_data['url']

title = bs.title.string

print('[A] 标题:' + title)

print('[A] 播放地址:' + m3u8_link)

print('_' * 70)

return m3u8_link, title

from bs4 import BeautifulSoup as bs

import re

import json

import requests

def get_m3u8_link(url):

# 直接正则匹配

print('_' * 70)

print('[A] 解析播放地址......')

html_doc = get_url_source_code(url)

bs = BeautifulSoup(html_doc, "html.parser")

pattern = re.compile(r"var cms_player = {(.*?);$", re.MULTILINE | re.DOTALL)

surls = bs.find('script', text=pattern)

js_string = str(surls.text).replace('var cms_player = ', '').replace(';', '')

json_data = json.loads(js_string)

m3u8_link = json_data['url']

title = bs.title.string

print('[A] 标题:' + title)

print('[A] 播放地址:' + m3u8_link)

print('_' * 70)

return m3u8_link, title

def get_m3u8_linkv2(self, url):

print('_' * 70)

print('[A] 解析播放地址......')

html_doc = self.http_get(url)

soup = bs(html_doc, "html.parser")

pattern = re.compile(r"var player_data={(.*?);$", re.MULTILINE | re.DOTALL)

player = soup.find('div', class_='myplayer')

surls = player.find('script')

# print(surls)

js_string = str(surls).replace('', '')

print(js_string)

json_data = json.loads(js_string)

m3u8_link = json_data['url']

title = soup.title.string

print('[A] 标题:' + title)

print('[A] 播放地址:' + m3u8_link)

print('_' * 70)

return m3u8_link, title

def get_m3u8_linkv2(self, url):

print('_' * 70)

print('[A] 解析播放地址......')

html_doc = self.http_get(url)

soup = bs(html_doc, "html.parser")

pattern = re.compile(r"var player_data={(.*?);$", re.MULTILINE | re.DOTALL)

player = soup.find('div', class_='myplayer')

surls = player.find('script')

# print(surls)

js_string = str(surls).replace('', '')

print(js_string)

json_data = json.loads(js_string)

m3u8_link = json_data['url']

title = soup.title.string

print('[A] 标题:' + title)

print('[A] 播放地址:' + m3u8_link)

print('_' * 70)

return m3u8_link, title

分享文章:

python爬取js script中的变量_BeautifulSoup抓取js变量相关推荐

  1. python百度贴吧怎么爬取最早的帖子_【Python爬虫教学】百度篇·手把手教你抓取百度贴吧任意贴吧指定范围页数内的源代码...

    开门见山. 懒癌一犯,能拖一天是一天. 好了,亲爱的小伙伴们,我又回来了!今天带来的是抓取输入的任意贴吧,抓取指定范围页数内的源代码. 工具: 依旧是 PyCharm 和 Google 浏览器,pyt ...

  2. python数据抓取技术与实战训练_师傅带徒弟学Python:项目实战1:网络爬虫与抓取股票数据...

    本视频基于**Python 3.X版本 本视频课程是第四篇第一个实战项目,内容包括网络爬虫技术.使用urllib爬取数据.使用Selenium爬取数据.使用正则表达式.使用BeautifulSoup库 ...

  3. python爬虫成长之路(一):抓取证券之星的股票数据

    python爬虫成长之路(一):抓取证券之星的股票数据 获取数据是数据分析中必不可少的一部分,而网络爬虫是是获取数据的一个重要渠道之一.鉴于此,我拾起了Python这把利器,开启了网络爬虫之路. 本篇 ...

  4. 不会 Python 没关系,手把手教你用 web scraper 抓取豆瓣电影 top 250 和 b 站排行榜

    苏生不惑第190 篇原创文章,将本公众号设为 星标 ,第一时间看最新文章. 关于Python之前分享过很多文章了: Python 抓取知乎电影话题下万千网友推荐的电影,这个国庆节不愁没电影看了 王菲k ...

  5. Python爬虫之XPath基础教程:用代码抓取网页数据

    Python爬虫之XPath基础教程:用代码抓取网页数据 在网络时代,网页数据是获取信息和进行分析的最重要的来源之一.Python的爬虫技术让我们可以轻松抓取网页数据,并进行数据处理.XPath是一种 ...

  6. 不会 Python 没关系,手把手教你用 web scraper 抓取豆瓣电影 top 250 和 b 站排行榜...

    苏生不惑第190 篇原创文章,将本公众号设为星标,第一时间看最新文章. 关于Python之前分享过很多文章了: Python 抓取知乎电影话题下万千网友推荐的电影,这个国庆节不愁没电影看了 王菲k歌又 ...

  7. 分享:Python使用cookielib和urllib2模拟登陆新浪微博并抓取数据

    Python使用cookielib和urllib2模拟登陆新浪微博并抓取数据 http://my.oschina.net/leopardsaga/blog/94774

  8. webscraper多页爬取_Web Scraper 高级用法——Web Scraper 抓取多条内容 | 简易数据分析 07...

    这是简易数据分析系列的第 7 篇文章. 在第 4 篇文章里,我讲解了如何抓取单个网页里的单类信息: 在第 5 篇文章里,我讲解了如何抓取多个网页里的单类信息: 今天我们要讲的是,如何抓取多个网页里的多 ...

  9. 「docker实战篇」python的docker-打造多任务端app应用数据抓取系统(下)(35)

    上次已经把python文件挂载到虚拟机上了,这次主要设置下虚拟机通过docker容器的方式. 运行 python 代码运行 >启动一个crt的会话 docker run -it -v /root ...

最新文章

  1. myeclipse中的js文件报错
  2. 扩容是元素还是数组_02 数组(附ArrayList源码分析)
  3. 1355: [Baltic2009]Radio Transmission
  4. angular2创建应用_如何在Angular 2+应用程序中使用JavaScript库
  5. 类Array对象中是否该直接使用Array的原型方法?
  6. 不同网站不同网卡_弄清高端网站建设的独特不同之处才能做好网站
  7. Java面向对象之多态解析、final关键字
  8. 日历2019全年日历表_实施和使用日历表
  9. 通过wifi使用nfs把ubuntu挂载到android
  10. Want VS Needs,产品经理基于场景的需求挖掘
  11. Pandas速查手册中文版API
  12. 【Proteus仿真】PIC12C672单片机+LM317可调数显稳压电源1.3V~25V
  13. SVN相关问题(svn:E175002错误)的解决方案
  14. 一张帖搞定同学们入学黑马前所有难题
  15. PLC是怎么工作的?工作原理是什么?
  16. ESP32 micropython 应用填坑(一):蓝牙
  17. CRM —— 1、搭建开发环境
  18. ChemDraw怎么调整键长?调整键长教程
  19. selenium执行js脚本
  20. HTML之表格,表单的使用

热门文章

  1. tomcat安装配置教程
  2. 沈逸老师PHP魔鬼特训笔记(3)
  3. iOS开发之保存照片到自己创建的相簿
  4. 312. Burst Balloons
  5. mongodb update ()命令
  6. linux 服务器网络有关的内核参数
  7. C++两种编写单件模式方法对比
  8. 不能不说的C#特性-表达式树
  9. [转载] python+selenium定时爬取丁香园的新冠病毒每天的数据,并制作出类似的地图(部署到云服务器)
  10. JDK9的安装与配置