推荐学习书目
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 · Jun 14, 2020 · 4299 views
    This topic created in 2186 days ago, the information mentioned may be changed or developed.

    最近有个网页整体翻译的需求,看了一下,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 replies    2020-06-16 23:08:58 +08:00
    DonnyChao
        1
    DonnyChao  
    OP
       Jun 14, 2020
    noqwerty
        2
    noqwerty  
       Jun 14, 2020   ❤️ 1
    Google 的 Cloud Translation 可以直接调 API 的: https://cloud.google.com/translate/docs/
    laoyur
        3
    laoyur  
       Jun 14, 2020   ❤️ 1
    处理 iframe 时,要先 driver.switch_to.frame(frames[0])一下才行
    9yu
        4
    9yu  
       Jun 14, 2020 via Android   ❤️ 1
    检查有没有 iframe
    xiri
        5
    xiri  
       Jun 14, 2020
    为什么不直接调用 API
    jizhihaoSAMA
        6
    jizhihaoSAMA  
       Jun 14, 2020
    iframe 正解
    DonnyChao
        7
    DonnyChao  
    OP
       Jun 14, 2020
    @laoyur
    @9yu

    是 iframe 原因,已按 3 楼方法解决。
    DonnyChao
        8
    DonnyChao  
    OP
       Jun 14, 2020
    @xiri Google 翻译 API 看网上教程说,不能翻译 HTML 文件,只能翻译文本
    sxd96
        9
    sxd96  
       Jun 15, 2020 via iPhone   ❤️ 1
    如果只是这个网页的话,你知不知道这有中文选项...
    polarpy
        10
    polarpy  
       Jun 15, 2020
    正解
    yucongo
        11
    yucongo  
       Jun 16, 2020 via Android
    用 Pyppeteer 吧,还能异步操作。有现成的基于 Pyppeteer 的包 https://pypi.org/project/deepl-tr-async/ pip install deepl-tr-async,可异步调 google 翻译或 deepl
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1041 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 19:05 · PVG 03:05 · LAX 12:05 · JFK 15:05
    ♥ Do have faith in what you're doing.