selenium 相关问题

Selenium是一种流行的开源工具,用于自动化Web浏览器。使用此标记时,还要包含您正在使用的特定组件的其他标记,例如selenium-webdriver用于语言绑定,selenium-ide,selenium-grid等。


如何使用seleniumpython

我想发送包含4000多个字符的文本,当我这样做时 粉碎并继续打开新标签(idk为什么),但是当我尝试发送600个字符时,它可以正常工作。 B ...

回答 2 投票 0

可以在没有无头模式的情况下在Amazon EC2实例上运行硒?

我想使用硒在不使用无头模式的情况下在Amazon EC2实例上加载PDF页面,因为我想加载PDF。由于此处描述的问题(https://github.com/puppeteer/puppeteer/issues/

回答 1 投票 0

如何滚动Google Map评论?

这里是博物馆的评论,我想刮擦:

回答 0 投票 0



如何让硒/python等待用户登录,然后继续运行? 我正在尝试在Selenium/Python中运行一个脚本,该脚本需要在脚本运行的其余部分才能在不同点上登录。 有什么办法让我告诉脚本停下来等待脚步...

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import unittest, time, re, getpass driver = webdriver.Firefox() driver.get("https://www.facebook.com/") someVariable = getpass.getpass("Press Enter after You are done logging in") driver.find_element_by_xpath('//*[@id="profile_pic_welcome_688052538"]').click()

回答 2 投票 0

在Maven中进行单个测试 - >未执行测试

当我用此命令在Maven中进行一次测试时: MVN测试-dtest = InitiatEteTest 我得到以下结果: 没有执行测试! 它在几分钟前起作用,但现在停止了...

回答 14 投票 0

我正在尝试刮擦一些Google数据,但我首先想单击Google弹出的“我同意”按钮。这是我用来这样做的脚本:

问题是硒似乎无法找到按钮,因此我会暂停错误。 (我也尝试使用find_element_by_xpath,但仍然无法正常工作)。

回答 6 投票 0



如何在python

我一直在尝试使用Python Selenium为我观看YouTube视频并收集数据。

回答 0 投票 0

使用Selenium Web驱动程序从Python

我必须从页面上的下拉列表中选择选项。我尝试了以下代码,但它显示了语法错误。有人可以帮我吗? web_element x = driver.find_element_by_xpath('//*[@ID =“

回答 4 投票 0


顺便说一句,不要使用抽搐API。 <video>有什么方法可以使用请求和BeautifulSoup4刮擦链接? 我想刮擦实际包含剪辑的“ SRC”属性的标签。但是,问题是,每当我尝试加载页面并使用请求 + BeautifulSoup4来寻找

import time from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.firefox.options import Options def get_clip_link(link): try: url = link options = Options() options.add_argument('--headless') driver = webdriver.Firefox(options=options) driver.get(url) time.sleep(3) page = driver.page_source driver.quit() soup = BeautifulSoup(page, 'html.parser') videos = soup.find_all('video') for video in videos: src = video['src'] if src: return src else: return False except: return False

回答 0 投票 0

子Chromedriver“ get”不可靠地加载@Importfonts

@导入URL(https://fonts.googleapis.com/css?family = droid+serif:400,700, 我有一些html页面: </desc><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&#34;utf-8&#34;&gt; &lt;style&gt;@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic); body { font-family: &#39;Droid Serif&#39;; }&lt;/style&gt; &lt;/head&gt; ... </code><question vote="4"> <p>用硒加载页面时:</p> <pre><code>from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argument(&#39;--kiosk-printing&#39;) browser = webdriver.Chrome(r&#34;chromedriver.exe&#34;, options=chrome_options) browser.get(&#34;http://www.example.com/&#34;) </code></pre> <p>到达:</p> <pre> </pre>50%的时间,字体不会加载(页面上显示默认的serif字体(时代新罗马))<p> </p>50%的时间,字体已加载<ul> <li> </li><li>如何使字体加载使用硒更可靠? </li>第二次重新加载页面</ul><code>time.sleep(2); browser.get(...)</code><p>没有帮助100%的时间。 <strong> </strong> </p>i偶然发现了upoun这个web api(<p>https://developer.mozilla.org/en-us/docs/web/api/fontfaceset<pre>)。 </pre>步调此代码:</p> </question><code> from selenium import webdriver import time u = &#39;https://fonts.google.com/&#39; driver = webdriver.Chrome(executable_path=r&#34;chromedriver.exe&#34;) driver.maximize_window() driver.get(u) while True: script = &#39;&#39;&#39;return document.fonts.status;&#39;&#39;&#39; loaded = driver.execute_script(script) if loaded == &#39;loaded&#39;: print(&#39;All fonts loaded&#39;) break print(&#39;Fonts still loading&#39;) time.sleep(.5) </code><answer tick="false" vote="2"> <p>必须说,就我而言,铬只有在页面满载(包括字体)时将控件返回到硒。 也许您可以提供最低限度的例子来测试您的50-50场景<a href="https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet" rel="nofollow noreferrer"> </a> </p> <p>我正面临着同样的问题,什么也不会裁员。 这是我的情况:</p> <pre><code>html_string = render_to_string(self.template_name, ctx) html_string = html_string.encode(&#39;utf-8&#39;).decode(&#39;utf-8&#39;) temp_file = &#34;/tmp/temp.html&#34; [...] driver = webdriver.Chrome(options=options) driver.get(&#34;file://&#34; + temp_file) [...] </code></pre> <p>没有任何东西会使字体加载。因此,我将它们复制到</p><code>/tmp</code></answer>目录中,以与<answer tick="false" vote="0"><code>.html</code><p></p>一起使用 <p><code># create directory in /tmp temp_fonts = Path(&#34;/tmp/fonts/&#34;) temp_fonts.mkdir(exist_ok=True) # loop through the fonts I am using in the .html for font in [&#39;georgia-semibold.ttf&#39;, &#39;Nunito-Bold.ttf&#39;, &#39;Nunito-Regular.ttf&#39;]: with open(temp_fonts / font, &#34;wb&#34;) as f: font_path = Path(settings.BASE_DIR) / &#34;static&#34; / &#34;fonts&#34; / font # copy the font into the /tmp/font directory f.write(open(font_path, &#34;rb&#34;).read()) </code></p> <pre>现在参考文献无瑕 </pre> <p><pre>

回答 0 投票 0




子 + python如何聆听元素的变化

该想法是创建一个bot来从聊天中读取消息,并且所有消息都在and(而不是必不可少的书写消息)中,例如 ul>lii从硒中找到<ul class="message-list"> <li class="message"> Hello There </li> <li class="message"> Hello </li> </ul> ,以处理是否存在/发现元素,但这始终是正确的,因为有一条消息,但是如果已经在聊天中,我不想继续代码,那不是主要想法。在那之后,我发现了expected_conditions,什么也没有。 EventFiringWebDriver, AbstractEventListener 我认为您可以编写一个循环,然后在循环中,在所需的“ ul”中获取“ li” s的数量。如果“李”的数量增加,您将有一个新消息。 from selenium import webdriver as wb from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener from selenium.webdriver.common.keys import Keys class MyListener(AbstractEventListener): def before_navigate_to(self, url, driver): print("Before navigate to %s" % url) def after_navigate_to(self, url, driver): print("After navigate to %s" % url) driver = wb.Chrome('C:\python\selenium\chromedriver.exe') wait = WebDriverWait(driver, 300) # ef_driver = EventFiringWebDriver(driver, MyListener()) driver.implicitly_wait(15) driver.get('https://socket.io/demos/chat/') driver.switch_to.frame(driver.find_element_by_class_name('iframe-class')) InputName = driver.find_element_by_xpath('/html/body/ul/li[2]/div/input') InputName.send_keys('MyNameIsJeff') InputName.send_keys(Keys.ENTER) 您可以在循环中进行某种侦听器,以检查消息元素的文本以确定它是否是新消息,您只需要确定要在“检查”之间等待的设定时间范围 - 10秒,30秒,1分钟等。 我认为您不需要活动的听众。您只需获取最新消息,然后继续检查它以查看它是否与以前的值不同。 # get list of li inside of ul ulList = driver.find_elements_by_xpath("//ul[@class='message-list']") lenOfLis = len(ulList) # wait for new message... while (true): ulList = driver.find_elements_by_xpath("//ul[@class='message-list']") if (len(ulList) > lenOfLis): # you have new message for (i in range(len(ulList)-lenOfLis)): yourLastMessage = ulList[-1-(i-1)] # you can do whatever you want with your last messages LenOfLis = len(ulList) # update length of ul # wait 15 seconds sleep(5) 此示例将获取当前显示的消息列表。然后,它抓住了最后一个收到的消息。该代码输入循环并重新查看消息列表,检查最后一个接收的消息,并将其文本与我们之前保存的最后一个消息值进行比较。 如果最后一个接收的消息与保存的值不同,则循环将断开,这意味着已经发布了新消息。 这里有一些不清楚的事情 - 最近的消息可能是list中的第一个元素或最后一个元素。另一个问题 - 您是否正在做一些事情来触发出现新消息?例如from time import sleep # get list of currently displayed messages messages = driver.find_elements_by_xpath("//li[@class='message']") # get text from most recent message # depending on element order on the page, might need to do messages.last last_message_text = messages[0].text # do something here to trigger a new message coming in? # wait for last_message_text to be something different while (true): # get list of currently displayed messages messages = driver.find_elements_by_xpath("//li[@class='message']") # new message has arrived if we hit this statement if (messages[0].text != last_message_text) break; # wait 15 seconds sleep(15) ?如果是这种情况,则代码的顺序可能需要更改。 lastly-在您的评论中,您提到有时是空的。我不太确定这是什么意思,但是如果某些消息出现并且页面上没有HTML,那么此解决方案将无法真正起作用。

回答 2 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.