这篇文章主要围绕在新标签页中打开WebSelenium+Python和在新标签页中打开链接展开,旨在为您提供一份详细的参考资料。我们将全面介绍在新标签页中打开WebSelenium+Python的优缺
这篇文章主要围绕在新标签页中打开Web Selenium + Python和在新标签页中打开链接展开,旨在为您提供一份详细的参考资料。我们将全面介绍在新标签页中打开Web Selenium + Python的优缺点,解答在新标签页中打开链接的相关问题,同时也会为您带来标签的onclick,在新标签页中打开另一个html文件、Angularjs $state在新标签页中打开链接、javascript-如何在新标签页中打开documentFragment、Python Selenium 新标签 Microsoft Edge的实用方法。
本文目录一览:- 在新标签页中打开Web Selenium + Python(在新标签页中打开链接)
- 标签的onclick,在新标签页中打开另一个html文件
- Angularjs $state在新标签页中打开链接
- javascript-如何在新标签页中打开documentFragment
- Python Selenium 新标签 Microsoft Edge
在新标签页中打开Web Selenium + Python(在新标签页中打开链接)
因此,我试图在WebDriver内的新选项卡上打开网站。我想这样做,因为使用PhantomJS为每个网站打开一个新的WebDriver大约需要3.5秒,所以我想提高速度…
我正在使用多进程python脚本,并且我想从每个页面中获取一些元素,因此工作流程如下:
Open BrowserLoop throught my arrayFor element in array -> Open website in new tab -> do my business -> close it
但是我找不到任何方法来实现这一目标。
这是我正在使用的代码。网站之间永远都需要花时间,我需要它很快。允许使用其他工具,但是我不知道有太多工具可以用来删除通过JavaScript加载的网站内容(在加载事件时触发div创建的div等)为什么我需要selenium… BeautifulSoup无法用于我的某些页面。
#!/usr/bin/env pythonimport multiprocessing, time, pika, json, traceback, logging, sys, os, itertools, urllib, urllib2, cStringIO, mysql.connector, shutil, hashlib, socket, urllib2, refrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom PIL import Imagefrom os import listdirfrom os.path import isfile, joinfrom bs4 import BeautifulSoupfrom pprint import pprintdef getPhantomData(parameters): try: # We create WebDriver browser = webdriver.Firefox() # Navigate to URL browser.get(parameters[''target_url'']) # Find all links by Selector links = browser.find_elements_by_css_selector(parameters[''selector'']) result = [] for link in links: # Extract link attribute and append to our list result.append(link.get_attribute(parameters[''attribute''])) browser.close() browser.quit() return json.dumps({''data'': result}) except Exception, err: browser.close() browser.quit() print errdef callback(ch, method, properties, body): parameters = json.loads(body) message = getPhantomData(parameters) if message[''data'']: ch.basic_ack(delivery_tag=method.delivery_tag) else: ch.basic_reject(delivery_tag=method.delivery_tag, requeue=True)def consume(): credentials = pika.PlainCredentials(''invitado'', ''invitado'') rabbit = pika.ConnectionParameters(''localhost'',5672,''/'',credentials) connection = pika.BlockingConnection(rabbit) channel = connection.channel() # Conectamos al canal channel.queue_declare(queue=''com.stuff.images'', durable=True) channel.basic_consume(callback,queue=''com.stuff.images'') print '' [*] Waiting for messages. To exit press CTRL^C'' try: channel.start_consuming() except KeyboardInterrupt: passworkers = 5pool = multiprocessing.Pool(processes=workers)for i in xrange(0, workers): pool.apply_async(consume)try: while True: continueexcept KeyboardInterrupt: print '' [*] Exiting...'' pool.terminate() pool.join()
答案1
小编典典你可以通过组合键COMMAND+ T
或COMMAND+ W(OSX)
实现标签的打开/关闭。在其他操作系统上,你可以使用CONTROL+ T/ CONTROL+ W
。
在硒中,你可以模仿这种行为。你将需要创建一个WebDriver
和所需的选项卡。
这是代码。
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Firefox()driver.get("http://www.google.com/")#open tabdriver.find_element_by_tag_name(''body'').send_keys(Keys.COMMAND + ''t'') # You can use (Keys.CONTROL + ''t'') on other OSs# Load a page driver.get(''http://stackoverflow.com/'')# Make the tests...# close the tab# (Keys.CONTROL + ''w'') on other OSs.driver.find_element_by_tag_name(''body'').send_keys(Keys.COMMAND + ''w'') driver.close()
标签的onclick,在新标签页中打开另一个html文件
仅需将链接的目标设置为空白,仅此而已。 见下文:
<html>
<head>
<body>
<a href="discussions.html" target="_blank">DISCUSSIONS</a>
</body>
</head>
</html>
,
如果您想在新标签页中打开链接:
<a href="https://example.com" target="_blank">some text</a>
或针对您域中的页面:
<a href="example.html" target="_blank">some text</a>
,
您想在其中放置一个链接^^
例如/dist/discussion.html”,如果您想将其指向另一个网站 在这个项目中
或http://google.com(如果您希望它重定向到另一个现有站点)
Angularjs $state在新标签页中打开链接
$state.go('routeHere',{ parameter1 : "parameter" },{ reload : true,newtab : true // or smth like target : "_blank" });
有没有办法使用AngularJS?
谢谢,
亚历克斯
var url = $state.href('myroute',{parameter: "parameter"}); window.open(url,'_blank');
javascript-如何在新标签页中打开documentFragment
有哪些选项可用于在新选项卡或窗口中打开文档片段.哪些浏览器最兼容,哪些最用户友好?
var frag = document.createDocumentFragment();
var div = $("<div>").addClass("Printable");
div[0].innerHTML = doc.body.innerHTML;
frag.appendChild(div[0]);
openIt(frag); // How to implement openIt
该片段包含准备打印的页面的重新格式化子集.
优选地,我希望它通过某种< link>自然打开.或< a>并像其他任何用户友好的html链接一样,而不是通过window.open安静地打开一个烦人的弹出窗口.
解决方法:
没有window.open(),您将无法可靠地执行此操作,即使那样,您仍需要在该文档上而不是当前文档上创建片段(因为某些浏览器不允许交叉添加元素.看起来像这样:
var win = window.open("","myWindow","...options...");
var frag = win.document.createDocumentFragment();
var div = win.document.createElement("div");
div.className = "Printable";
div.innerHTML = doc.body.innerHTML;
frag.appendChild(div);
You can test out a demo here.
Python Selenium 新标签 Microsoft Edge
如何解决Python Selenium 新标签 Microsoft Edge?
所以我想使用 python selenium 模块自动化 Microsoft Edge 我想使用 chrome 但我不知道为什么每当我在我的电脑上打开 chrome 我的电脑会自动关闭所以我使用 Microsoft Edge。我想出了如何使用 Microsoft Edge 制作驱动程序以及如何使用 Microsoft Edge 打开网站,但我的问题是如何在新选项卡中显示链接:
为了理解我的问题,这里有一些代码:
from msedge.selenium_tools import Edge,EdgeOptions
class Driver:
def __init__(self):
options = EdgeOptions()
options.use_chromium = True
self.driver = Edge(options=options)
def go_to_link(self,*url):
for i in url:
self.driver.get(i)
def close(self):
self.driver.close()
def quit(self):
self.driver.quit()
links = ["https://www.google.co.in/","https://www.youtube.com/","https://stackoverflow.com/"]
Driver = Driver()
Driver.go_to_link(*links)
Driver.quit()
所以我希望每个链接都显示在 Microsoft Edge 的新选项卡中,任何人都可以帮助我吗?
如果有人帮助,如果他们不能,我真的很感激。
解决方法
您可以循环进入所有链接,如下所示:
links = ["https://www.google.co.in/","https://www.youtube.com/","https://stackoverflow.com/"]
number_of_tabs = len(links)
count = 1
for link in links :
driver.get(link)
windows_before = driver.current_window_handle
driver.execute_script("window.open('''');")
#WebDriverWait(driver,10).until(EC.number_of_windows_to_be(number_of_tabs))
new_window = driver.window_handles[count]
count = count + 1
driver.switch_to.window(new_window)
sleep(3)
我们今天的关于在新标签页中打开Web Selenium + Python和在新标签页中打开链接的分享已经告一段落,感谢您的关注,如果您想了解更多关于标签的onclick,在新标签页中打开另一个html文件、Angularjs $state在新标签页中打开链接、javascript-如何在新标签页中打开documentFragment、Python Selenium 新标签 Microsoft Edge的相关信息,请在本站查询。
本文标签: