Created
November 4, 2018 11:52
-
-
Save harukaeru/6048361a11473b9678138e636e24de96 to your computer and use it in GitHub Desktop.
Extract data as TSV from glossary in Weblio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tdFunctions = { | |
0: td => td.getAttribute('title'), | |
1: td => td.innerHTML, | |
2: td => td.querySelector('.tngMainTIML').innerHTML, | |
3: td => td.querySelector('.tngMainTSRHB').textContent, | |
} | |
var trFilter = tr => { | |
return tr.classList.contains('tngMainTrOn'); | |
} | |
var extract = (tBodyElement, tdFunctions, trFilter) => { | |
const arrayIndices = Object.keys(tdFunctions); | |
const lastArray = arrayIndices.length - 1; | |
let ret = ""; | |
for (var i =0; i < tBodyElement.children.length; i++) { | |
var tr = tBodyElement.children[i]; | |
if (trFilter(tr)) { | |
let row = ""; | |
arrayIndices.forEach((i, ii) => { | |
if (ii == lastArray) { | |
row += tdFunctions[i](tr.children[i]) + "\n"; | |
} else { | |
row += tdFunctions[i](tr.children[i]) + "\t"; | |
} | |
}) | |
ret += row; | |
} | |
} | |
console.log(ret); | |
} | |
extract(document.querySelector('#wordlist-main-content-table-body'), tdFunctions, trFilter); |
何度実行しても
Traceback (most recent call last):
File "toAnki.py", line 16, in
pronunciation = array_line[1]
IndexError: list index out of range
と出てしまうのですが何か解決策はあるでしょうか?
教えていただけると幸いです
すいません、解決しました
この表示がでてもちゃんとtsvファイルが変換されるみたいですね
とても便利なのでこれからも使わさせていただきます!
ありがとうございました!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Additional
Here is the sample file I indicated the above Demo. You can try downloading this and import it according to concise instructions of the following.
https://www.mediafire.com/file/h1v71mo919vm3pt/weblio2.tsv.converted.tsv/file
Instructions
Click the button
Import File
on Anki (You may not use this function on mobile apps, I recommend you prepare the Anki app on a PC or Mac.)The following window will be coming up. It may be useful if you choose a Deck. I suggest you create a new Deck. (I created
Sample
Deck in this example.)After imported, enjoy it!