页面代码:

< 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. scala中的部分应用函数和偏函数的区别
  2. python利用unittest进行测试用例执行的几种方式
  3. spring 注解上传文件 @RequestParam,FormData上传文件
  4. 【线性回归】面向新手的基础知识
  5. ​分布式数据库技术基础:数据分布介绍
  6. mysql 二叉树表设计_mysql---B+tree索引的设计原理
  7. Castle ActiveRecord学习实践(1)入门
  8. Jquery—JQuery对select的操作(01)
  9. ST NFC+MTK平台
  10. 《ANSYS Workbench有限元分析实例详解(静力学)》——2.5 Windows界面相应操作
  11. 电解电容串联的均压电阻计算
  12. html源代码中 图像的属性标记,HTML图像标签img和源属性src及Alt属性、宽高、对齐...
  13. 计算机考研用python_本科化工考研跨考计算机,学过高数和Python,难度有多大?...
  14. 通用AI元素识别在UI自动化测试的最佳实践
  15. NPDCCH发送周期解析
  16. Go学习笔记 -- 通道实现协程等待
  17. Spring Boot 解决同名类导致的bean名冲突bean name conflicts
  18. 微信小程序抽奖 简单功能实现
  19. 一个refine/refactor的例子
  20. 使用adb连接夜神模拟器,查看多开模拟器端口号

热门文章

  1. [转]centos7.2 下 nginx 开机启动
  2. python库--requests
  3. 2016-Fiddler
  4. webservice wsdl 生成服务
  5. JS+CSS实现Dock menu(MacOS菜单导航效果)
  6. [转载] numpy.minimum
  7. [转载] python3 numpy函数_Python numpy总结(3)——常用函数用法
  8. 数据结构与算法(Python)第二天
  9. FPGA基础知识之主要的FPGA生产厂商介绍
  10. asp数据分页显示技术(上下页版)