【发布时间】:2021-09-04 18:58:05
【问题描述】:
我正在做一些业余网络抓取,但在通过 xpath 获取值时遇到了问题。我的目标是https://kek.tools/t/0x4e15361fd6b4bb609fa63c81a2be19d873717870。我的代码如下:
def scrape_price():
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
driver.get('https://kek.tools/t/0x841fad6eae12c286d1fd18d1d525dffa75c7effe')
driver.implicitly_wait(100)
price = driver.find_element_by_xpath('//input[@class="sc-ciSkZP sc-bjHqKj bwSYJA dbQnLk" and @tabindex="2"]')
print(price.get_attribute("value"))
driver.quit()
//input[@class="sc-ciSkZP sc-bjHqKj bwSYJA dbQnLk" and @tabindex="2"] 的检查元素过滤似乎得到了我需要的确切输入字段,但是当我打印值时总是返回“1”。我没有为WebElement 使用正确的方法吗?
【问题讨论】:
标签: python selenium web-scraping xpath getattribute