File size: 1,468 Bytes
538ada5 11884d9 538ada5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import requests
import json
import re
import gradio as gr
import cloudscraper
scraper = cloudscraper.create_scraper()
def getlivejson(url):
pattern = re.compile(r'show/(.*)')
numbers = pattern.findall(url)
infoid =numbers[0]
purl="https://weibo.com/l/!/2/wblive/room/show_pc_live.json?live_id=" + infoid
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'Accept':'application/json, text/plain, */*',
'Referer':url
}
response = requests.get(purl, headers=headers)
retinfo= json.loads(response.text)
return retinfo["data"]["replay_origin_url"]
def getyoujiaurl(url):
cookie='BDUSS=1; BAIDUID=4; CITY=%7B%22code%22%3A%22131%22%2C%22name%22%3A%22%E5%8C%97%E4%BA%AC%22%7D; MAWEBCUID=2; YOUJIAID=3:FG=1;'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'Accept':'application/json, text/plain, */*',
'Cookie':cookie
}
response = requests.get(url, headers=headers)
return response.text
def getcloudscraper(url):
response=scraper.get(url).text
return response
demo = gr.Interface(
fn=getcloudscraper,
inputs="text",
outputs="text",
)
demo.launch()
# url="https://weibo.com/l/wblive/p/show/1022:2321325026359016816923"
# info=getlivejson(url)
# print(info)
|