用于实现通过牌子逆向查主播信息这个功能。
插件基于Nonebot2开发,链接:https://github.com/Ikaros-521/nonebot_plugin_searchBiliInfo
github:https://github.com/Ikaros-521/get_bili_medal_list
gitee:https://gitee.com/ikaros-521/get_bili_medal_list
data.py数据源自vtbs.moe
1.py用于获取数据
2.py用于中断时候的下标检索
data_medal.py用于存储用户结果数据
https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser?from=0¬_mock_enter_effect=1&room_id= 传入主播的房间号,解析json["data"]["medal"]["up_medal"]["medal_name"],即可。
安装相应的第三方库(aiohttp)后,python 1.py 即可。
import json
import asyncio
import aiohttp
import time
from itertools import islice
# data.py存储着从vtbs.moe获取的主播数据
from data import DATA
# data_medal.py用于存储获取的主播牌子信息
from data_medal import DATA_MEDAL
# 用于存储牌子数据
data_medal_json = DATA_MEDAL
# 请求头
header1 = {
'content-type': 'text/plain; charset=utf-8',
# 下方填入你的cookie喵
'cookie': "",
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.186.400 QQBrowser/11.3.5195.400'
}
# 计数用
num = 0
# 获取主播牌子信息 传入主播房间号
async def get_medal(roomid):
global header1
API_URL = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser?from=0¬_mock_enter_effect=1&room_id=' + str(roomid)
async with aiohttp.ClientSession(headers=header1) as session:
try:
async with session.get(url=API_URL, headers=header1) as response:
if response.status != 200:
response.raise_for_status()
ret = await response.json()
except aiohttp.ClientError as e:
print(e)
# 睡眠个3s
await asyncio.sleep(3)
# 重试一次
async with session.get(url=API_URL, headers=header1) as response:
if response.status != 200:
response.raise_for_status()
ret = await response.json()
return ret
async def main():
global data_medal_json, num
# print(type(DATA))
# 遍历本地vtb数据 第二个参数的起始值,跳过前n个数据(这个下标可以通过2.py获取已加载到的下标)
for data in islice(DATA, 4849, None):
print(data)
try:
roomid = data["roomid"]
except (KeyError, TypeError, IndexError) as e:
print(e)
continue
if roomid == 0:
continue
# 睡眠个0.5s
await asyncio.sleep(0.5)
json1 = await get_medal(roomid)
# print(json1)
try:
if json1["code"] != 0:
print(json1)
continue
# 获取牌子名
medal_name = str(json1["data"]["medal"]["up_medal"]["medal_name"])
# 拼接新的json串
temp_json = { medal_name: data }
try:
# 判断是否已经存在
if temp_json in DATA_MEDAL:
print("已存在 " + medal_name + " 跳过")
continue
else:
# 追加入json
data_medal_json.append(temp_json)
except (KeyError, TypeError, IndexError) as e:
print(e)
continue
# 计数+1
num += 1
print("获取牌子名:" + medal_name)
# 每获取10个结果 写入一次数据文件
if num % 10 == 0 and num != 0:
filename = 'data_medal.py'
with open(filename, 'w', encoding="utf-8") as file_object:
file_object.write("DATA_MEDAL = " + json.dumps(data_medal_json, ensure_ascii=False))
file_object.close()
print("num=" + str(num) + ", 写入" + filename)
except (KeyError, TypeError, IndexError) as e:
print(e)
continue
filename = 'data_medal.py'
with open(filename, 'w', encoding="utf-8") as file_object:
file_object.write("DATA_MEDAL = " + json.dumps(data_medal_json, ensure_ascii=False))
file_object.close()
print("num=" + str(num) + ", 写入" + filename)
print("数据爬取完毕了,收工回家~")
if __name__ == "__main__":
asyncio.run(main())
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur