简体   繁体   English

如何在 selenium python 中单击多个产品 url

[英]How click multiple product url in selenium python

I am learning selenium.我正在学习 selenium。 I am trying to find-out how I can open all of product details page from this page by using selenium python.我试图找出如何使用 selenium python 从该页面打开所有产品详细信息页面。 Right now it can extract all product url but I want it will open all of product details page.现在它可以提取所有产品 url 但我希望它会打开所有产品详细信息页面。 How I can do it?我该怎么做? here given my code这里给出了我的代码

from selenium import webdriver
import time

browser = webdriver.Chrome("/Users/Downloads/chromedriver")
browser.get("https://www.daraz.com.bd/womens-shalwar-kameez/?spm=a2a0e.home.cate_8.3.73521b94OBZ8sj")
time.sleep(5)

numbers = browser.find_elements_by_css_selector('div.c16H9d a')
for ii in numbers:
    print(ii.get_attribute("href"))


time.sleep(4)
browser.close()

Instead of getting "href", this is assuming from your script all of the numbers contain href.这不是获取“href”,而是从您的脚本中假设所有数字都包含href。

Below script should open new tab for each links.下面的脚本应该为每个链接打开新标签。 Please check the below syntax first before running on your machine在您的机器上运行之前,请先检查以下语法

for elem in numbers:
    link = numbers.get_attribute("href")
    browser.execute_script('''window.open(" + link + ","_blank");''')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM