明日复明日,明日何其多。
我生待明日,万事成蹉跎。

autojs爬取单词

// 开始运行
sleep(1000);
if (currentPackage() != "cn.com.langeasy.LangEasyLexis") {
	launch("cn.com.langeasy.LangEasyLexis");
}
console.show();
// ===================分隔符===================
id('ll_learn_band').click() && log("点击->Learn")
	log("DDDD")
textContains("美").waitFor()
	log("CCCC")
sleep(200)

	log("BBBB")
// 考义词汇
var optList = id('ll_isknow').findOne(500)
if (optList != null && optList.childCount() == 2) {	log("BBAA")

	id('tv_know').findOne().click() && log("点击->认识")
}
// id('tv_unknow').click() && log("点击->看答案")
// id('tv_lookupExample').click() && log("点击->原生例句")

	log("AAAA")
// 爬取
	log("0000")
var wordTxt = id('tv_acceptation').findOne().text()
var character = ""
var wordIdx = 0
while (true) {
	var continueBtn = id('left_button').findOne(500)
	if (continueBtn != null) {
		sleep(300)
		continueBtn.click() && log("点击->再来一组")
	}

	// 保存例句
	log(1111)
	var word = {}
	word.word = id('tv_word').findOne().text()
	log(2222)
	var pronTv = id('prononce_display').findOne(500)
	log(3333)
	word.pron = pronTv != null ? pronTv.text() : ""
	log(4444)
	// 判断是否为生词
	var wordOpt = id('rl_learn_option').findOne()
	log(5555)
	var collection = wordOpt.findByText('看答案')
	log(6666)
	var isNew = collection != null && collection.size() > 0 
	log(7777)
	if (isNew) {
	log(8888)
		var showDict = id('iv_show_dict').findOne(500)
	log(9999)
		if (showDict != null) {
			showDict.click() && log("点击->打开字典")
			textContains("在历年真题中出现").waitFor()
			word.frequency = textMatches("^\\d+").find().reverse()[0].text()
			id('close_button').findOne().click()
			textContains("美").waitFor()
		}
		swipe(216, 1230, 864, 1230, 100) && log("侧滑->看词缀")
		var affix = id('type_content').findOne(500)
		if (affix != null) {
			word.affix = affix.text()
			swipe(864, 1230, 216, 1230, 100) && log("侧滑->退出例句")
		}
		wordIdx = 0
		textContains("美").waitFor()
		swipe(864, 930, 216, 930, 100) && log("侧滑->看例句")
	} else {
		// 第二次答题
		var iKnow = id('tv_know').findOne(500)
		if (iKnow != null) {
			iKnow.click() && log("点击->认识")
			continue
		}
	}

	var isKey = id('interpret_type').textContains('扩展词义').find().size() < 2
	if (isKey) {
		sleep(200)
		log('考义单词')
		word.mean = id('tv_acceptation').findOne().text()
		let lastEn
		for (var i = 1; i <= 3; i++) {
			try {
				var exKey = "example" + i
				var exEn = id('en_sentence').find().get(i).text()
				// 若为相同例句则退出循环
				if (exEn != null && exEn == lastEn) {
					log("当前例句重复 退出遍历")
					break
				}
				word[exKey + "_en"] = exEn
				word[exKey + "_cn"] = id('ch_sentence').find().get(i).text() +
					"--- (" + id('s_book_title').find().get(i).text() + ")"
			} catch (err) {
				log("err" + err)
			}
			lastEn = exEn
			var scrollAble = id('sentence_vp').findOne().scrollForward()
			if(!scrollAble) break;
			sleep(500)
		}
		// 这里我用了一个接口去存储 是写入mysql数据库的 你们可以自己实现
		/*
		参数示例
		{
		    "word": "word2",
		    "mean": "mean2",
		    "pron": "pron2",
		    "frequency": 22,
		    "example1_en": "example1_en2",
		    "example1_cn": "example1_cn2",
		    "example2_en": "example2_en2",
		    "example2_cn": "example2_cn2",
		    "example3_en": "example3_en2",
		    "example3_cn": "example3_cn2"
		}
		*/
		var url = "http://xxx.xxx/api/meaning";
		// log(word)
		r = http.postJson(url, word);
		toastLog(r.body.string());
	} else {
		log('非考义单词')
	}

	// 判断是否最后一个词义
	var pageIndex = id('page_index').find().reverse()[0].text()
	var arr = pageIndex.split('/')

	// 保存第一个中文 用于答题
	if (wordIdx == 0) {
		var firstMean = id('tv_acceptation').findOne().text().replace(/\(.*\)/g, '').replace(/(.*)/g, '').replace(/[|;|,]/g, '')
		var index = escape(firstMean).indexOf("%u");
		character = escape(firstMean).substring(index, index + 6);
		character = unescape(character)
		log("character:" + character)
		log("firstMean:" + firstMean)
	}

	// 非考义 OR 最后一页 则收起卡片 
	if (!isKey || arr[0] == arr[1]) {
		textContains("美").waitFor()
		// 收起例句卡片
		log('当前为最后一页')
		var lookupExample = id('tv_lookupExample').findOne(500)
		if (lookupExample != null) {
			lookupExample.click() && log("点击->收起卡片")
		}

		// 移除单词
		var removeWord = id('iv_del').findOne(500)
		if (removeWord != null) {
			removeWord.click() && log("点击->移除单词")
		}

	} else {
		wordIdx++;
		id('detail_card_view').findOne().scrollForward() && log("滑动->下一词义")
	}
}

// ===================分隔符===================
// 结束
sleep(500);
exit();
log("难道脚本还没停止吗?");
CREATE TABLE `bubei_meaning` (
  `word` varchar(64) NOT NULL COMMENT '单词',
  `mean` varchar(64) NOT NULL COMMENT '意思',
  `pron` varchar(64) NOT NULL COMMENT '音标',
  `frequency` int NOT NULL DEFAULT '0' COMMENT '词频',
  `example1_en` varchar(255) NOT NULL,
  `example1_cn` varchar(255) NOT NULL,
  `example2_en` varchar(255) NOT NULL,
  `example2_cn` varchar(255) NOT NULL,
  `example3_en` varchar(255) NOT NULL,
  `example3_cn` varchar(255) NOT NULL,
  PRIMARY KEY (`word`,`mean`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
赞(0) 打赏
未经允许不得转载:致明日 » autojs爬取单词
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

坚持,总会看见蓝天和白云

联系我们你来了,你就是最棒的!

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏