python抓取直播源 并更新_虎牙直播源Python爬虫

这段源码可以爬的是虎牙“一起看”的版块即轮播电影那个区域的,其他版块的需要自行修改。import requests

import re

import json

from lxml import etree

class Huya_live:

def __init__(self):

# self.list_url = []

self.id = []

self.headers = {

"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",

}

def get_m3u8(self):

for id in self.id:

url = "https://www.huya.com/" + id

response = requests.get(url, headers=self.headers)

html = response.text

# title = re.findall("

.*|\r\n", html)[0]

html_etree = etree.HTML(html)

title = html_etree.xpath('//h1[@id="J_roomTitle"]/text()')[0]

title = re.sub("

||\r|\n", "", title)

regex = re.compile(r"{.*}")#匹配{}格式的内容

strs = re.findal

你可能感兴趣的:(python抓取直播源,并更新)