V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
DonnyChao
V2EX  ›  Python

Python + selenium 也获取不了这个网页的源码

  •  
  •   DonnyChao · 2020-06-14 22:48:11 +08:00 · 3455 次点击
    这是一个创建于 1383 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近有个网页整体翻译的需求,看了一下,Google 网页翻译是最优解,但是使用 selenium 也获取不了网页翻译后的源码。

    网页对象链接( Google 网页翻译页面): https://translate.google.com.hk/translate?hl=&sl=en&tl=zh-CN&u=https://docs.python.org/3/tutorial/index.html

    使用 selenium 取这个网页的源码,但是只能获取到 head 源码,body 主要的信息获取不到,请问有什么方法能获取到整个页面的源码吗?

    [img]https://p.pstatp.com/origin/ff450002d304a982cd55[/img]

    11 条回复    2020-06-16 23:08:58 +08:00
    DonnyChao
        1
    DonnyChao  
    OP
       2020-06-14 22:48:42 +08:00
    noqwerty
        2
    noqwerty  
       2020-06-14 22:51:57 +08:00   ❤️ 1
    Google 的 Cloud Translation 可以直接调 API 的: https://cloud.google.com/translate/docs/
    laoyur
        3
    laoyur  
       2020-06-14 22:52:42 +08:00   ❤️ 1
    处理 iframe 时,要先 driver.switch_to.frame(frames[0])一下才行
    9yu
        4
    9yu  
       2020-06-14 22:52:53 +08:00 via Android   ❤️ 1
    检查有没有 iframe
    xiri
        5
    xiri  
       2020-06-14 22:59:33 +08:00
    为什么不直接调用 API
    jizhihaoSAMA
        6
    jizhihaoSAMA  
       2020-06-14 23:04:01 +08:00
    iframe 正解
    DonnyChao
        7
    DonnyChao  
    OP
       2020-06-14 23:06:02 +08:00
    @laoyur
    @9yu

    是 iframe 原因,已按 3 楼方法解决。
    DonnyChao
        8
    DonnyChao  
    OP
       2020-06-14 23:07:06 +08:00
    @xiri Google 翻译 API 看网上教程说,不能翻译 HTML 文件,只能翻译文本
    sxd96
        9
    sxd96  
       2020-06-15 01:59:16 +08:00 via iPhone   ❤️ 1
    如果只是这个网页的话,你知不知道这有中文选项...
    polarpy
        10
    polarpy  
       2020-06-15 11:37:46 +08:00
    正解
    yucongo
        11
    yucongo  
       2020-06-16 23:08:58 +08:00 via Android
    用 Pyppeteer 吧,还能异步操作。有现成的基于 Pyppeteer 的包 https://pypi.org/project/deepl-tr-async/ pip install deepl-tr-async,可异步调 google 翻译或 deepl
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1148 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:00 · PVG 07:00 · LAX 16:00 · JFK 19:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.