使用selenium的网站所有链接中的词频

2024-09-20 22:52:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写代码,以便使用Selenium自动计算给定链接的字数。我在driver.get()中提供了URL。我使用了find_elements_by_xpath,它将返回一个链接列表。我想做的是爬到每个链接,找到像“机器学习”,“深度学习”等词的频率,并打印在excel表格中的单词频率。你知道吗

我已经提取了链接。我该如何进一步。你知道吗

from selenium import webdriver
import os 

driverLocation = "C:\\Users\\Shishir\\workspace\\libs\\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = driverLocation
driver = webdriver.Chrome(driverLocation)
driver.get("https://www.servicenow.com/solutions-by-category.html")

#Get elements by Xpath
links = driver.find_elements_by_xpath("//a[@href]")
for elem in links:
    #print all the links 
    print(elem.get_attribute("href"))

Tags: importgetbyos链接driverelementslinks

热门问题