selenium 我怎么才能从某个开发者那里得到应用程序的链接,直到现在我已经放弃了Web对象,但无法得到实际的链接?

vm0i2vca  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(114)

我试图从Playstore上的特定开发人员提取所有应用程序的链接。

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver. common.by import By

driver = webdriver.Chrome (executable_path=ChromeDriverManager().install())
driver.get("https://play.google.com/store/apps/dev?id=5305197572942248936")
l1 = driver.find_elements(By.CLASS_NAME, 'ULeU3b')
vc9ivgsu

vc9ivgsu1#

您已接近解决方案。
在您找到的元素中,有包含链接的a元素。
这里所需要的只是等待所有这些元素变为可见,获取这些元素的列表,遍历列表并提取链接。
下面的代码是有效的:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")
options.add_argument('--disable-notifications')

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 20)

url = "https://play.google.com/store/apps/dev?id=5305197572942248936"
driver.get(url)

links = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".ULeU3b a")))
for link in links:
    print(link.get_attribute("href"))

其结果是:

https://play.google.com/store/apps/details?id=com.tatamotors.eguruibcrm
https://play.google.com/store/apps/details?id=com.T1.Primarun
https://play.google.com/store/apps/details?id=com.tata.skoolman
https://play.google.com/store/apps/details?id=com.ttl.tatafleetman

相关问题