简体   繁体   English

在 python 中下载网页源的最简单方法是什么? (javascript 已应用后)

[英]What's the easiest way to download the source of a webpage in python? (After javascript has been applied)

In python:在 python 中:

I want to download the source of a webpage, after the javascript has been applied.我想下载一个网页的源代码,在应用了javascript之后。 What's the easiest way to do that?最简单的方法是什么?

splinter is the easiest way to do this: splinter是最简单的方法:

from splinter.browser import Browser
browser = Browser()
browser.visit('http://google.com')

splinter is a tool that makes using several mature products much easier to use. splinter是一种工具,它使使用多种成熟产品变得更容易使用。 Things like Selenium require lots of getting used to.像 Selenium 这样的东西需要很多时间来适应。 splinter allows you to learn one API to use the webdriver or change to zope.testbrowser if you would like to. splinter允许您学习一个 API 以使用 webdriver 或更改为 zope.testbrowser 如果您愿意。

You can run JavaScript and alter the page or test its results:您可以运行 JavaScript 并更改页面或测试其结果:

browser.execute_script("$('body').empty()")
browser.evaluate_script("4+4") == 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM