调用google机器翻译翻译文章
1.把需要翻译的文件保存在数据库上.
2.自动控制pagedown到页面
3.保存翻译的结果到数据库
4.chrome 需要载入配置
fy(line,i): = = options = webdriver.ChromeOptions() options.add_argument() driver = webdriver.Chrome(=options) driver.get(line) driver.execute_script() time.sleep() page = driver.find_element_by_xpath().get_attribute() (page) f = (+(i)+,) f.writelines(page) f.close() driver.close() f = () lines = f.readlines() num = line lines: fy(line,num) num=num+
#-*- coding:utf-8 -*-
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import time,os
NULL = '\ue000'
PAGE_DOWN = '\ue00f' #PgDwon 键
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users/jim/Library/Application Support/Google/Chrome")
driver = webdriver.Chrome(options=options)
driver.get("https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/")
driver.execute_script("""
(function () {
var y = document.body.scrollTop;
var step = 100;
window.scroll(0, y);
function f() {
if (y < document.body.scrollHeight) {
y += step;
window.scroll(0, y);
setTimeout(f, 50);
}
else {
window.scroll(0, y);
document.title += "scroll-done";
}
}
setTimeout(f, 1000);
})();
""")
#for letter in 'Python1111111111111111111111111':
# driver.find_element_by_xpath('/html/body').send_keys(PAGE_DOWN)
# time.sleep(1)
time.sleep(15)
page = driver.find_element_by_xpath("//*").get_attribute("outerHTML")
print(page)
f = open('test1.html','w')
f.writelines(page)
f.close()
driver.close()
- 点赞
- 收藏
- 关注作者
评论(0)