我想从戴尔的网站上提取一些我对我的设备感兴趣的日期。我尝试使用下载网页,urllib但它受验证码保护,我现在无法绕过它。现在我使用Selenium打开浏览器,手动解决capthca,然后自动打开页面并提取日期。问题是 css 选择器返回了一些奇怪的元素而不是所需的输出
我的代码:
from selenium import webdriver
import time
driver = webdriver.Chrome()
def scrape(codes):
dates = []
for i in range(len(codes)):
driver.get("https://www.dell.com/support/home/us/en/19/product-support/"
"servicetag/%s/warranty?ref=captchasuccess" % codes[i])
# Solve captcha manually
if i == 0:
print("You now have 120\" seconds to solve the captcha")
time.sleep(120)
print("120\" Passed")
# Extract data
expdate = driver.find_element_by_css_selector("#printdivid > div > div.not-annotated.hover > table:nth-child(3) > tbody > tr > td:nth-child(3)")
print(expdate)
driver.close()
codes = ['1FMR762', '15FDBG2', '10V8YZ1']
scrape(codes)
预期输出:
June 22, 2018
October 15, 2017
April 19, 2017
给定输出:
<selenium.webdriver.remote.webelement.WebElement (session="d83af0f7a3a9c79307d2058f863a7ecb", element="0.21873872382745052-1")>
<selenium.webdriver.remote.webelement.WebElement (session="d83af0f7a3a9c79307d2058f863a7ecb", element="0.06836824093097027-1")>
<selenium.webdriver.remote.webelement.WebElement (session="d83af0f7a3a9c79307d2058f863a7ecb", element="0.6642161898702734-1")>
相关分类