selenium批量翻译

时间:2021-03-31 06:22:41

Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门

https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6EmUbbW&id=564564604865

selenium翻译会打开多个浏览器,效率很低,适合模拟登陆,不适合批量翻译

翻译结果

selenium批量翻译

selenium批量翻译

import requests,bs4,selenium
from selenium import webdriver words_list=["python","job","hello world"]
translation_list=[]
#selenium抓取信息太慢,要打开浏览器
def Get_translation(word):
browser=webdriver.Firefox()
url="http://dict.youdao.com/w/%s/#keyfrom=dict.index"%(word)
browser.get(url)
elem=browser.find_elements_by_class_name("trans-container")
translation=elem[0].text
return translation def Get_all_translation(words_list):
for word in words_list:
try:
translation=Get_translation(word)
translation_list.append(translation)
except:
print("exception:",word)
continue