私信  •  关注

Prophet

Prophet 最近创建的主题
Prophet 最近回复了
4 年前
回复了 Prophet 创建的主题 » Python Selenium和BS

您必须在单击后增加延迟 next_page.click() 之前 content = driver.page_source.encode('utf-8').strip()
不建议使用硬编码睡眠。
更好的方法是获取前一页上显示的数据,然后使用某种预期条件等待前一页数据不再显示。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.XPATH,element_located_by_previous_value)))
4 年前
回复了 Prophet 创建的主题 » 如何在Facebook上搜索并单击Python selenium中的第一个结果

第一个结果(person)可以通过以下css选择器找到:

first_person_search_result = driver.find_element_by_css_selector('.qu0x051f.f10w8fjw.jb3vyjys')
3 年前
回复了 Prophet 创建的主题 » selenium python只获得第一个图像链接

该页面最初仅加载1个图像。
要获得更多图像,必须滚动页面。
因此,无需滚动页面,即可使用

images = driver.find_elements_by_css_selector('#shopify-section-product-template .Image--lazyLoaded')

中只有一个元素 images 列表
UPD
您可以单击左侧的dot导航,然后获得图像:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".Product__SlideshowNavScroller")))
time.sleep(0.2)
dots = driver.find_elements_by_css_selector('.Product__SlideshowNavScroller a')
image_src = set()
for dot in dots:
    dot.click()
    time.sleep(1)
    images = driver.find_elements_by_css_selector('#shopify-section-product-template .Image--lazyLoaded')
    for image in images:
        image_src.add(image.get_attribute('data-original-src'))

image_src 最终将包含所有图片src链接

这个弹出窗口在屏幕上 shadow dom .
Selenium不提供使用影子DOM元素的显式支持,因为它们不在当前DOM中。这就是为什么我们会 NoSuchElementException 尝试访问`shadow dom中的元素时出现异常。
对于以下JavaScript,这应该可以工作:

driver.get(r'https://www.studydrive.net/')
time.sleep(5)
accept_all_btn = driver.execute_script('''return document.querySelector('#usercentrics-root').shadowRoot.querySelector('button[aria-label="Accept All"]')''')
accept_all_btn.click()

查看更多解释 here here

3 年前
回复了 Prophet 创建的主题 » Python/Selenium get_元素问题

有几个可能的问题:

  1. 在尝试访问元素之前,您可能错过了让页面加载的等待/延迟。
  2. 元素可能位于iframe内部,因此必须切换到该iframe才能访问其中的元素。
  3. 定位器可能不是唯一的。
    为了给出更清晰的答案,我们需要查看您正在使用的we页面以及所有相关代码
3 年前
回复了 Prophet 创建的主题 » 无法单击元素,请单击Python

operate2a5a0448a8bf44a8898ec13e95b152fc 似乎是动态创建的id。
访问此元素的最简单方法是使用基于文本的XPath定位器:

wait2.until(EC.element_to_be_clickable((By.XPATH, "//div[contains(text(),'Entry Registration')]"))).click()
5 年前
回复了 Prophet 创建的主题 » 在python中获取输入和接收输出后如何再次请求输入

在第二个代码片段中,在第二个输入之后不执行任何操作。也许你忘了再打电话给forloop了?我可以按照你说的做。 以下这些对你有用吗?当然,使用函数更优雅。

x = int(input())  

for i in range(2,x):  
    if(x % i ==0):      
        print("not Prime")  
        break  
else :  
    print("Prime")  

x = int(input())

for i in range(2,x):
    if(x % i ==0):
        print("not Prime")
        break
else :  
    print("Prime")

这就是我的魅力

enter image description here