Python 3.x Python:可以用PhantomJS下载整个网页吗
我用幻影来刮东西。我想知道是否有可能下载URL的所有内容(包括图像、CSS和JS)并保存在本地以供浏览Python 3.x Python:可以用PhantomJS下载整个网页吗,python-3.x,phantomjs,Python 3.x,Phantomjs,我用幻影来刮东西。我想知道是否有可能下载URL的所有内容(包括图像、CSS和JS)并保存在本地以供浏览 # -*- coding: utf-8 -*- from selenium import webdriver #for cookies collections after all AJAX/JS being executed from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from s
# -*- coding: utf-8 -*-
from selenium import webdriver #for cookies collections after all AJAX/JS being executed
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36")
driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false'])
driver.set_window_size(1366,768)
driver.get('http://stackoverflow.com')
driver.page_source
这是使用Python Selenium+PhantomJS的完整代码,最后您拥有完整的页面源代码。我们可以使用evaluate()函数获取内容。我在nodejs中使用这个
var webPage = require('webpage');
var page = webPage.create();
page.open('http://google.com', function(status) {
var title = page.evaluate(function() {
return document.title;
});
console.log(title);
phantom.exit();
});`
在安装wget的情况下,此任务相当简单:
domain = "www.google.de"
from subprocess import call
call(["wget", "-mk", domain])
我说了整个页面包括资产。问题更新我不知道(也许你必须迭代所有标签,然后加载这些文件,然后保存到你的服务器上。我知道这是最后的选择,我想知道是否已经存在一些库。你不能只使用PhantomJs下载文件,添加文件下载支持已经有很长时间了,但他们似乎并不在意。所有这些都说明,@Umair aproach可能很有用,使用bf4,你可以得到你想要的任何元素,然后使用请求加载它们。好吧,是Python吗?不是dude。它的节点是。@volatil3。你可以检查这个链接。你安装了wget吗?