以《Light: Science & Applications》期刊为例,获取其最新的论文信息并翻译。——python代码。
from googletrans import Translator
from DrissionPage import ChromiumPage
from DrissionPage.common import Keys
def ggtran(text,dest,src):
"""
googletrans api 翻译调用
:param text: 要翻译的原文
:param dest: 翻译后输出的语言种类
:param src: 原文的语言种类(auto为默认识别)
:return: 翻译后的内容
"""
translater = Translator()
result = translater.translate(text, dest, src)
print(f"摘要: {result.text}")
return result
page = ChromiumPage()
# page.get换成自己的地址
page.get('https://idp-personal-authenticator.springernature.com/gateway?response_type=code&redirect_uri=https%3A%2F%2Fidp.springernature.com%2Fauthed%2Fsso&state=eyJjdHkiOiJKV1QiLCJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiZGlyIn0..n6PRvdfGBeL2cyhN.mptF8C5LuntagbuV_HPBnQX-SvAl4SciqDWie2b3g-KUecaO5THm-Wmi7GRlGS2kr3S0N8oi7k0kgTUyKk-tTIyoeAYKNnrA6LLmEBi30Nh5Z6jg7WZigJhYQIVi3Vr7nsN5-3hWj2u26RCG2bsa_URkqBiFlIdi4pVBeAa8tMM9RxXAR8mU_ktKjNKOc2R14dfA2WjkDZ1OLrS2icYWo_GfFDIuXte9xqZEIfqo7n80gACjOiriUS2V4DHqpFPrn6agjzUXAw31nDVPNYonOn8BxA0YdeQK5GSO9ItaDsMirvgEV3ypZfkHZGKpOutlSHaokQ0eceqZgj6QoZkarAht57DuqHL0yMMobFAqnhgeyPlY5KhDSpvgpGhBwd7PdCRVMVpFWV2ptpuGxPUGqUt-pGEXxvQGuMO8FtvpHdNy1JzBXUXa-dL6Ul06u6Osh2QLvZZfoHZWR7dTT6qXVzNsqDd63e_xNnW9v4ybevvMA97il-L76YcvCVIEJxIfdEcP-C8mbXAXr8EEONwHM7A5ie39SbeSANDjqXld_pmyOBUToOMbT45MN7ZyPES14wqyNdjVUAU4XK2KIePNMAwy-930jXCtte6Zb7FrqCz_sYnPR9YLoh-p5hbmUQnTUQyB7hBxfRr1BqQKEFmrg9fC7XBjDSmE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farticles%3Ftype%3Darticle')
print(page.title, id(page))
ele = page.ele('#login-email')
# 换成自己的账户
ele.input('****@gmail.com')
page.ele('#email-submit').click()
tab = page.latest_tab
ele = tab.ele('#login-password')
ele.clear()
# 换成自己的密码
ele.input('usk*****k5i5b')
tab.ele('#password-submit').click()
print(tab.title, id(tab))
tab = page.latest_tab
tab = page.latest_tab
ele = page.ele('#login-email')
ele.input('***@gmail.com')
page.ele('#email-submit').click()
tab = page.latest_tab ele = tab.ele('#login-password')
ele.clear()
# 换成自己的密码
ele.input('us****kTPb')
tab.ele('#password-submit').click()
links = tab.eles('.c-card__link u-link-inherit')
date = tab.eles('@itemprop=datePublished')
date_texts = [ele.text for ele in date]
print(tab.mode)
tab.change_mode()
print(tab.mode)
i = 0
url=[]
for link in links:
url.append(link.link)
for a in url:
tab.get(a)
ele = tab.ele('@data-test=article-title')
print(f"{i+1}.题目: {ele.text}")
print(f"发表日期: {date_texts[i]}")
authors = tab.eles('@data-test=author-name')
author_texts = [ele.text for ele in authors]
print(f"作者: {author_texts}")
ele = tab.ele('#Abs1-content')
ggtran(text={ele.text}, dest='zh-cn', src='auto')# 中译英
print(f"网址链接: {a}")
i = i +1