如何解析包含javascript代码的html
如何解析大量使用javascript的html文档?我知道python中有几个库可以解析静态xml/html文件,我基本上是在寻找一个程序或库(甚至是firefox插件),它可以读取html+javascript,执行javascript位并输出不带javascript的html代码,因此如果显示在浏览器中,它看起来会完全相同 举个简单的例子如何解析包含javascript代码的html,javascript,python,html,Javascript,Python,Html,如何解析大量使用javascript的html文档?我知道python中有几个库可以解析静态xml/html文件,我基本上是在寻找一个程序或库(甚至是firefox插件),它可以读取html+javascript,执行javascript位并输出不带javascript的html代码,因此如果显示在浏览器中,它看起来会完全相同 举个简单的例子 <a href="javascript:web_link(34, true);">link</a> 应替换为javascri
<a href="javascript:web_link(34, true);">link</a>
应替换为javascript函数返回的适当值,例如
<a href="http://www.example.com">link</a>
一个更复杂的例子是一个保存的facebook html页面,其中充斥着大量javascript代码
可能与
但是我真的需要Node.js和JSDOM吗?也有轻微的关联
但我对仅呈现纯html输出不感兴趣。来自:
你能从unixshell脚本中调用Gecko引擎吗?你能把它发送到HTML并得到一个可能被发送到打印机的网页吗
A.没有得到真正的支持;不过,通过使用Gecko的嵌入API编写自己的应用程序,您可能会得到一些接近您想要的东西。请注意,如果屏幕上没有要渲染的小部件,则当前无法打印
在一个程序中,输出你想要的东西可能太重了,但至少你的输出会和它得到的一样好。你可以详细地使用python
例如:
import xmlrpclib
# Make an object to represent the XML-RPC server.
server_url = "http://localhost:8080/selenium-driver/RPC2"
app = xmlrpclib.ServerProxy(server_url)
# Bump timeout a little higher than the default 5 seconds
app.setTimeout(15)
import os
os.system('start run_firefox.bat')
print app.open('http://localhost:8080/AUT/000000A/http/www.amazon.com/')
print app.verifyTitle('Amazon.com: Welcome')
print app.verifySelected('url', 'All Products')
print app.select('url', 'Books')
print app.verifySelected('url', 'Books')
print app.verifyValue('field-keywords', '')
print app.type('field-keywords', 'Python Cookbook')
print app.clickAndWait('Go')
print app.verifyTitle('Amazon.com: Books Search Results: Python Cookbook')
print app.verifyTextPresent('Python Cookbook', '')
print app.verifyTextPresent('Alex Martellibot, David Ascher', '')
print app.testComplete()
可以使用
获取JavaScript运行时并对其进行排序,或者分析代码并确定最终结果(强烈按站点配置)。还可以添加以下配方:
$ ipython
In [1]: from selenium import webdriver
In [2]: browser=webdriver.PhantomJS()
In [3]: browser.get('http://seleniumhq.org/')
In [4]: browser.title
Out[4]: u'Selenium - Web Browser Automation'