惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - cutepig

換博客了,新地址https://cutepig123.github.io/ 光盘是个好东西 俺买过的电子产品 抽象的好与坏 垂直方向的努力更有意义 python GUI test tool AirtestIDE_2019-04-16_py3_win64 冯唐论加班 Prometheus 文件系统api为何可以这么简洁以及我們這個抓圖模塊的設計難點 好繫統是一次性設計出來的嗎 jaeger tracing CS lessons c++ 书籍 my codes 我写的代码 写了一个自动用google翻译文档的工具 用几种语言实现socks server 一個不錯的Modern CMake的入門教程 Modern CMake remote ssh for vscode test
google translate automation using selenium
cutepig · 2021-02-15 · via 博客园 - cutepig
import os, sys, requests
from selenium import webdriver

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time


def translate(browser):
    wait = WebDriverWait(browser, 10)  # 等待加载10s

    url = 'https://translate.google.com.hk/?hl=en&tab=rT&sl=en&tl=zh-CN&op=translate'
    browser.get(url)

    input = wait.until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[1]/span/span/div/textarea')))
    time.sleep(3)
    input.send_keys('hello world')

    output = wait.until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]')))
    time.sleep(3)
    print(output)
    print(output.get_attribute("innerText"))
    

if 1:
    # Not work
    #chrome_options = webdriver.ChromeOptions()
    #chrome_options.add_argument("--disable-popup-blocking")

    #browser = webdriver.Chrome(options=chrome_options)
    browser = webdriver.Chrome()

    browser.maximize_window()  # 最大化窗口
    wait = WebDriverWait(browser, 10)  # 等待加载10s

    # txtTemp, btnSubmit
    translate(browser)

# pass!
if 0:
    driver = webdriver.Chrome()
    driver.get("http://www.python.org")
    assert "Python" in driver.title
    elem = driver.find_element_by_name("q")
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    print (driver.page_source)