- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用以下代码使用 Python 保存网页:
import urllib
import sys
from bs4 import BeautifulSoup
url = 'http://www.vodafone.de/privat/tarife/red-smartphone-tarife.html'
f = urllib.urlretrieve(url,'test.html')
问题:此代码将 html 保存为没有 javascript、图像等的基本 html。我想将网页保存为完整的(就像我们在浏览器中有选项一样)
更新:我现在使用以下代码来保存 webapge 的所有 js/images/css 文件,以便它可以保存为完整的网页,但我的输出 html 仍然像基本 html 一样保存:
import pycurl
import StringIO
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://www.vodafone.de/privat/tarife/red-smartphone-tarife.html")
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.perform()
html = b.getvalue()
#print html
fh = open("file.html", "w")
fh.write(html)
fh.close()
最佳答案
尝试使用 selenium 模拟您的浏览器.该脚本将弹出网页的 save as
对话框。您仍然需要弄清楚如何模拟按 Enter 以开始下载,因为文件对话框超出了 selenium 的范围(您的操作方式也取决于操作系统)。
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
br = webdriver.Firefox()
br.get('http://www.google.com/')
save_me = ActionChains(br).key_down(Keys.CONTROL)\
.key_down('s').key_up(Keys.CONTROL).key_up('s')
save_me.perform()
我也认为遵循 @Amber 的建议来获取链接的资源可能更简单,因此是更好的解决方案。不过,我认为使用 selenium 是一个很好的起点,因为 br.page_source
将为您提供整个 dom 以及 javascript 生成的动态内容。
关于python - 如何使用 Python 保存 "complete webpage"而不仅仅是基本的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516590/
我的应用程序有一个在客户端运行的 websocket 客户端,我正在使用 websocket 上传文件。 我有一个 wicket 网页,它有两种上传 USB 文件的方法(自动和输入类型文件)当我的页面
当我们尝试在 sitecore 7.1 应用程序中浏览图像时,出现以下错误,该错误已从 6.2 迁移到 7.1。 Type 'ASP._Page_sitecore_shell_client_Speak
在从 6.2 迁移到 7.1 的 Sitecore 7.1 中打开图像时,出现以下错误: Type 'ASP._Page_sitecore_shell_client_Speak_Layouts_Lay
我得到: Type 'ASP._Page_index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'. 当我浏览到我的index
我在配置 asp.net mvc 应用程序时遇到问题: [HttpException (0x80004005): Type 'ASP._Page_Currency_Index_cshtml' does
我遵循了非常相似的帖子提供的答案,您将在下面列出的逐步步骤中看到。 Razor view Type does not inherit from 'System.Web.WebPages.WebPage
这个问题在这里已经有了答案: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to... web.conf
我正在我的 Android 应用程序上集成 payumoney 支付网关。但是当我尝试通过测试借记卡进行测试交易时。它显示一个错误。当我联系 payumoney 客户服务时,他们说将服务器的 URL
我有一个网页,每 5 秒左右通过从服务器获取数据在 AJAX 中 self 更新。但是,我想只在用户主动查看页面时执行更新。 当用户在另一个选项卡上,在浏览器以外的另一个程序中,或者页面不是用户 PC
Google 是如何制作每天替换 Google Logo 的小动画的? 我知道去年全世界在工作中玩吃 bean 人时损失了将近 500 万小时(但这是值得的 :D)。但是这些互动小游戏还是让我印象深刻
我的本地主机上有一个 HTML 文件,我想要整个页面的屏幕截图。有谁知道一些截取整个页面(本地主机)的软件?我找到了一些插件,但它们不支持本地主机文件。 最佳答案 在 Windows 上按“Prt
我正在使用 PhantomJS 1.8.2 通过 JsTestDriver 运行一些 Jasmine 单元测试。使用 Chrome 测试运行良好,但使用 PhantomJS 时大约有一半的时间,测试结
我的本地主机上有一个 HTML 文件,我想要整个页面的屏幕截图。有谁知道一些截取整个页面(本地主机)的软件?我找到了一些插件,但它们不支持本地主机文件。 最佳答案 在 Windows 上按“Prt
import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface;
我需要点击一个链接,它实际上是 html 文件中的一个图像(左上角的 UCR 标志),我应该怎么做? 我有以下代码: url % follow_link("") 标志的html代码是:
为什么会这样? public class MainActivity extends Activity { WebView browser; @Override publ
我的来源: public class MainActivity extends DroidGap { @Override public void onCreate(Bu
我在godaddy购买了一个域名(www.domainname.com)。 我有一个 tomcat 服务器在路径 http://174.xxx.x.xx/WebApp1/webhome 部署了工作应用
我正在尝试完成一些可能相对简单的事情,但我不知道我会怎么调用它(如果有特定的名称),因此我的搜索被证明是无用的。 我想要完成的很简单:我有一个基于 Masonry jquery 插件(类似于 http
是否有任何自动化工具可以在网站上找到损坏的内部链接——特别是针对基于 DNN 框架的网站。 (DotNetNuke)。 我们查看了 Xenu,但看不到登录页面。 任何建议 干杯。 最佳答案 我已经在博
我是一名优秀的程序员,十分优秀!