Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
e0f2522
·
verified ·
1 Parent(s): f621273

战双帕弥什 @ wiki.biligame

Browse files
v-corpus-zh/库洛/战双帕弥什/0.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function copyTextToClipboard(text) {
2
+ setTimeout(async () => {
3
+ if (navigator.clipboard && window.isSecureContext) {
4
+ // 使用 Clipboard API
5
+ navigator.clipboard.writeText(text).then( () => {
6
+ console.log('Text copied to clipboard');
7
+ }
8
+ ).catch(err => {
9
+ console.error('Failed to copy text: ', err);
10
+ }
11
+ );
12
+ } else {
13
+ console.error('Failed to copy text: ');
14
+ }
15
+ }
16
+ , 3000);
17
+ }
18
+
19
+ let a = document.querySelector("#mw-content-text > div > div.zs-DialogTab > div.TabContainer > div.tab_con.active")
20
+ let b = []
21
+ for (const child of a.children) {
22
+ if (child.tagName.toLowerCase() !== 'div') {
23
+ continue;
24
+ }
25
+ b.push(decodeURIComponent(child.children[0].href));
26
+ }
27
+ copyTextToClipboard(b.join('\n'));
v-corpus-zh/库洛/战双帕弥什/1.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # conda install conda-forge::lxml conda-forge::httpx
2
+ import httpx, asyncio
3
+ from lxml import etree
4
+ from urllib.parse import unquote
5
+ from m08_runAfter import runAfter
6
+
7
+ after = runAfter()
8
+
9
+
10
+ def readfile(path):
11
+ with open(path, 'r', encoding='utf-8') as f:
12
+ return [line.rstrip('\r\n') for line in f if line.startswith('http')]
13
+
14
+
15
+ def writefile(path, lines):
16
+ with open(path, 'a', encoding='utf-8') as f:
17
+ for line in lines:
18
+ f.write(line)
19
+ f.write('\n')
20
+
21
+
22
+ q = asyncio.Queue()
23
+
24
+ for _ in enumerate(readfile('url.txt')):
25
+ q.put_nowait(_)
26
+
27
+
28
+ def txt2header(_path: str):
29
+ with open(_path, 'r', encoding='utf-8') as f:
30
+ _txt = f.read()
31
+ res = {}
32
+ tmp = _txt.strip().split('\n')
33
+ for i in range(0, len(tmp), 2):
34
+ res[tmp[i].rstrip(': ')] = tmp[i + 1]
35
+ return res
36
+
37
+
38
+ header = txt2header('header.txt')
39
+
40
+
41
+ async def get(url, decoding='utf-8'):
42
+ async with httpx.AsyncClient() as s:
43
+ response = await s.get(url, headers=header)
44
+ res_text = response.content.decode(encoding=decoding, errors='ignore')
45
+ return etree.HTML(res_text)
46
+
47
+
48
+ def parse(html, prefix='', _i=0):
49
+ html = html.xpath(r'//*[@id="mw-content-text"]/div/div[2]/div[2]/div')[0]
50
+ res = []
51
+ for i, a in enumerate(html.xpath(r'a')):
52
+ href = r'https://wiki.biligame.com' + unquote(a.attrib['href'], encoding='utf-8')
53
+ res.append('%d|%d|%s<|sp|>%s<|sp|>%s' % (_i, i, prefix, a.attrib['title'], href))
54
+ return res
55
+
56
+
57
+ async def loop():
58
+ i, url = await q.get()
59
+ for _ in range(3):
60
+ try:
61
+ html = await get(url)
62
+ urls = parse(html, url.split('/')[-1], i)
63
+ writefile('1.txt', urls)
64
+ after(2, loop)
65
+ break
66
+ except Exception as e:
67
+ print(i, url, e)
68
+
69
+
70
+ for _ in range(5):
71
+ after(0, loop)
72
+
73
+ q.empty()
v-corpus-zh/库洛/战双帕弥什/2.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def readfile(path):
2
+ with open(path, 'r', encoding='utf-8') as f:
3
+ return [line.rstrip('\r\n') for line in f if not line.startswith('\n')]
4
+
5
+
6
+ def writefile(path, lines):
7
+ with open(path, 'a', encoding='utf-8') as f:
8
+ for line in lines:
9
+ f.write(line)
10
+ f.write('\n')
11
+
12
+
13
+ import re
14
+
15
+ r = re.compile(r'^(\d+?)\|(\d+?)\|(.*?)<\|sp\|>(.*?)<\|sp\|>(.*?)$')
16
+
17
+ tmp = readfile('1.txt')
18
+
19
+ tmp.sort(key=lambda x: tuple(map(int, r.findall(x)[0][:2])))
20
+
21
+ writefile('2.txt', tmp)
v-corpus-zh/库洛/战双帕弥什/3.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import httpx, asyncio, os
2
+ from m08_runAfter import runAfter
3
+
4
+ after = runAfter()
5
+
6
+
7
+ def readfile(path):
8
+ with open(path, 'r', encoding='utf-8') as f:
9
+ return [line.rstrip('\r\n') for line in f if not line.startswith('\n')]
10
+
11
+
12
+ import re
13
+
14
+ r = re.compile(r'^(\d+?)\|(\d+?)\|(.*?)<\|sp\|>(.*?)<\|sp\|>(.*?)$')
15
+
16
+ q = asyncio.Queue()
17
+
18
+ for _ in readfile('2.txt'):
19
+ q.put_nowait(r.findall(_)[0])
20
+
21
+
22
+ def txt2header(_path: str):
23
+ with open(_path, 'r', encoding='utf-8') as f:
24
+ _txt = f.read()
25
+ res = {}
26
+ tmp = _txt.strip().split('\n')
27
+ for i in range(0, len(tmp), 2):
28
+ res[tmp[i].rstrip(': ')] = tmp[i + 1]
29
+ return res
30
+
31
+
32
+ header = txt2header('header.txt')
33
+
34
+
35
+ async def get(url, s, decoding='utf-8'):
36
+ # async with httpx.AsyncClient() as s:
37
+ response = await s.get(url, headers=header)
38
+ res_text = response.content.decode(encoding=decoding, errors='ignore')
39
+ return res_text
40
+
41
+
42
+ async def loop(s=None):
43
+ if s is None:
44
+ s = httpx.AsyncClient()
45
+ i, j, _, _, url = await q.get()
46
+ if os.path.exists(f'3/{i}_{j}.html'):
47
+ after(2, loop, s)
48
+ return
49
+ for _ in range(3):
50
+ try:
51
+ html = await get(url, s)
52
+ with open(f'3/{i}_{j}.html', 'w', encoding='utf-8') as f:
53
+ f.write(html)
54
+ after(2, loop, s)
55
+ break
56
+ except Exception as e:
57
+ print(i, j, url, e)
58
+
59
+
60
+ for _ in range(20):
61
+ after(_, loop)
v-corpus-zh/库洛/战双帕弥什/4.py ADDED
The diff for this file is too large to render. See raw diff
 
v-corpus-zh/库洛/战双帕弥什/4.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2e00d4e61c9f6a4060ce46cd05f8bff84f2e7f93e4b94b48ed61122a55283ef
3
+ size 5169533
v-corpus-zh/库洛/战双帕弥什/m08_runAfter.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import inspect
3
+ from threading import Thread
4
+
5
+
6
+ class runAfter:
7
+
8
+ def event_loop(self):
9
+ asyncio.set_event_loop(self.loop)
10
+ self.loop.run_forever()
11
+ self.loop.close()
12
+
13
+ def __init__(self, intervals=0.001):
14
+ self.loop = asyncio.new_event_loop()
15
+ self.ep = Thread(target=self.event_loop, daemon=True)
16
+ self.ep.start()
17
+
18
+ def __call__(self, intervals, callback, *args):
19
+ task = self.try_call(callback, args)
20
+ if intervals <= 0:
21
+ self.run(task)
22
+ return
23
+ self.loop.call_later(intervals, self.run, task)
24
+
25
+ def run(self, task):
26
+ asyncio.run_coroutine_threadsafe(task, self.loop)
27
+
28
+ async def try_call(self, callback, args):
29
+ try:
30
+ task = callback(*args)
31
+ if inspect.iscoroutine(task):
32
+ self.run(task)
33
+ except Exception as e:
34
+ print(e)
35
+
36
+
37
+ if __name__ == '__main__':
38
+ import time
39
+ after = runAfter()
40
+
41
+
42
+ async def aprint(*args):
43
+ print(*args)
44
+
45
+
46
+ after(0, print, 'aa', 'bb')
47
+ time.sleep(0.1)
48
+ after(3, aprint, 3)
49
+ after(2, print, 2)
50
+ time.sleep(0.1)
51
+ after(1, aprint, 1)
52
+ after(0, print, 'cc', 'dd')
53
+ after(0, aprint, 'ee', 'ff')
54
+ time.sleep(5)