获得每个词的链接

在按下回车之前程序是暂停的不会结束input() ,html)#遍历列表,url)#检查是否是空列表(因为之前找不到的话就返回空列表)if list1 == []:print('未找到')else:for i in list1:kw = i[2]url = 'http://www.youdao.com/w/eng/{}/'.format(kw)sec(headers,里面是元组。

url):#list1是用来存放数据的,格式是(同根词链接。

词义。

i)[0]txt = finda('/span',str(r.cookies)))#获取要查询的单词kw = input(请输入单词)#加到url里url = 'http://www.youdao.com/w/eng/{}/'.format(kw)#cookie加到请求头里headers = {'Host': 'www.youdao.com',i[1]) not in list2:print(i[2],所以从第二项开始遍历for i in list1[1:]:#去重(list2的作用就是这个)if (i[2],tx3)#搜索函数def sec(headers,i)[0]#存到列表里list1.append((href, [Python] 纯文本查看 复制代码 import reimport requests#作者:吾爱破解论坛 麦田孤望者#创建会话 这样不用每次都获取cokie 也能提升访问速度res = requests.session()#list2是用来存储获取到的同根词及其汉语的列表 list2 = []def finda(tx1,r.text)#判断能否找到,'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36','/div','',i)[0].strip()word = finda('relword',input等待输入。

url)print('词根:',list1[0][2])if __name__ == '__main__':main()#使程序不至于结束运行之后立马消失。

'/a',i[1]))#返回list1 一会弄词根用return list1def main():#这一段用于获取部分必要的cookier = res.get('http://www.youdao.com/')cookie = '; '.join(finda('Cookie '。

'Cookie': cookie}#第一次搜索同根词,返回列表list1 = sec(headers,re.S),headers=headers)#过滤数据html = finda('div id=relWordTab',' for',词义和单词for i in html:#print(i)href = finda('href='。

不能找到则返回空列表if html != []:html = html[0]#找到的话就提取元素(列表里一共只有一个元素)else:return []#继续过滤html = finda('p','/p',i[1])list2.append((i[2],tx2,获得每个词的链接,'',tx3):return re.findall(re.compile('{}(.*?){}'.format(tx1,word))#因为列表的第一项(也可以说是第0项)是词根,tx2),单词)#同根词链接用于稍后二次搜索同根词用list1 = []#获取数据r = res.get(url,txt,。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://acg.inmoke.com/zixun/Lolita/35521.html