百度翻译爬虫,基于selenium
from selenium import webdriver from selenium.webdriver.common.by import By class Transer: def __init__(self): self.d = webdriver.Firefox() self.d.implicitly_wait(3) self.d.get('https://fanyi.baidu.com/#en/zh/') self.d.find_element(By.XPATH, '/html/body/div[1]/div[6]/div/div/div[2]/span').click() def t(self, words): self.d.get('https://fanyi.baidu.com/#en/zh/'+words) return self.d.find_element(By.XPATH, '//*[@id="main-outer"]/div/div/div[1]/div[2]/div[1]/div[2]/div/div/div[1]/p[2]/span').text