【发布时间】:2022-01-13 19:15:43
【问题描述】:
# import selenium
from selenium import webdriver
# lets you use the any by element statements
from selenium.webdriver.common.by import By
# start the webdriver for chrome
from selenium.webdriver.chrome.service import Service
# import locate_with for above, below
from selenium.webdriver.support.relative_locator import locate_with
# declare the path as the service using the letter s
s = Service('C:\ChromeDriver\chromedriver.exe')
# declare the web driver using the service as the browser
driver = webdriver.Chrome(service=s)
# declare the URL
url = 'https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321'
# get the url referenced above using the browser.get
driver.get(url)
# tells the driver to wait 10 seconds so the page can load the "DOM"
driver.implicitly_wait(10)
VN = driver.find_element(By.XPATH, '//h1').text
print("System Impacted: " + VN)
CVSS = driver.find_element(By.XPATH, '//*[@id="title"]/div/div/div/div[3]/div[1]/div/div/label').text
print("CVSS Detail is: " + CVSS)
**AV = driver.find_element(By.XPATH, '//summary[normalize-space()="Network"]').text
print("Attack Vector: " + AV)**
我正在尝试扫描 URL 并获取有关“攻击向量”字段的相关信息
其中之一是在不同漏洞中找到攻击向量的价值 - https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321
对于 CVE,每个 xpath 都不同,例如:
//summary[normalize-space()="Network"] or
//summary[normalize-space()="Local"] or
//summary[normalize-space()="Physical"]
当我每次为 CVE 输入不同的 URL 时,我想打印出其中一个攻击向量,具体取决于 URL 捕获的与 CVE 关联的攻击向量的内容
【问题讨论】:
-
你到底卡在哪里了?哪条线?
-
AV = driver.find_element(By.XPATH, '//summary[normalize-space()="Network"]').text print("攻击向量:" + AV) 我希望它根据漏洞链接打印“网络”、“本地”或“物理”。对于实例“msrc.microsoft.com/update-guide/vulnerability/CVE-2021-43209”,攻击向量将是“本地”。
-
//div[@role='gridcell' and .//summary[contains(.,'Attack Vector')]]/following::div[1]//summary 总能找到攻击向量之后的摘要,无论是网络、本地还是物理。
-
我收到了这个错误:AV = driver.find_element(By.XPATH, '//div[@role='gridcell' and .//summary[contains(.,'Attack Vector')] ]/following::div[1]//summary').text ^^^^^^^^^^^^^^^^^^^^^ SyntaxError: 无效语法。也许您忘记了逗号?
-
使用 "//div[@role='gridcell' 和 .//summary[contains(.,'Attack Vector')]]/following::div[1]//summary"
标签: python selenium automation