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); |
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
何度実行しても
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
The extracted data is used as the element in the following script, which generates an Anki-format TSV file.
https://gist.github.com/harukaeru/4d799d14e6c1a9c6c21683dcc8f99bb2