-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add moehu support #56
Conversation
python script import requests
import re
from bs4 import BeautifulSoup
"""
2023.3.30 版本
"""
res = requests.get("https://img.moehu.org/")
bs = BeautifulSoup(res.text, 'html.parser')
menu_divs = bs.find_all(class_='menuDiv')[:-3]
# 最终返回的 json 数据
key_map = {}
for menu in menu_divs:
menu_ul = menu.find_next('ul')
for pre in menu_ul.find_all('pre'):
name, id_ = re.search(r'\((.*?)→.*id=(.*?)".*?>', str(pre)).groups()
key_map[name] = id_ |
I asked ChatGPT and it gave me the following code do the same thing as the code you posted, see if this work. If so, I think it can be also merged into the code base to used for get the id list. 我询问了 ChatGPT 然后它给了我以下的代码,和你发布的代码做了同样的事情,看看它是否工作。如果是的,我想它也可以被合并到代码库里,用于获取 id 列表。 import * as request from 'request';
import * as cheerio from 'cheerio';
/**
* 版本日期:2023.3.30
*/
const url = 'https://img.moehu.org/';
request(url, (error, response, body) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(body);
const menuDivs = $('.menuDiv').slice(0, -3);
// 最终返回的 json 数据
const keyMap: Record<string, string> = {};
menuDivs.each((index, menu) => {
const menuUl = $(menu).next('ul');
menuUl.find('pre').each((_, pre) => {
const match = $(pre).html()?.match(/\((.*?)→.*id=(.*?)".*?>/);
if (match) {
const [, name, id] = match;
keyMap[name] = id;
}
});
});
// 使用 keyMap 进行后续操作
console.log(keyMap);
}
}); Another possible improvement is to read the first tag (in Chinese) only and compare it with cached keys in the map above, then convert it to the actual id. 另一个可能的提升是只读取第一个标签(在中文),然后将它和上面快取的地图中的钥匙进行对比,然后转换到真实的 id。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upgrade dependencies
PR HealthBuild ✅Detailsyarn run v1.22.22
$ yakumo build
Done in 2.92s. |
Co-authored-by: KBLonay <[email protected]>
fix #50