Selenium 返回空字符串而不是实际数据 [英] Selenium returns empty string instead of the actual data

查看:32
本文介绍了Selenium 返回空字符串而不是实际数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 Python 使用 Selenium 来尝试网络抓取.我几乎到了我想去的地方,但我遇到了我现在意识到的问题.所以我正在使用的元素是这样的:

I am using Selenium via Python in attempts to web scrape. I'm almost where I want to be but I ran into what I am now realizing is not so small of a problem. So the element I am working with is this:

<td class=" ui-datepicker-days-cell-over  ui-datepicker-current-day ui-datepicker-today" 
data-handler="selectDay" data-event="click" data-month="3" data-year="2018">
    <a class="ui-state-default ui-state-highlight ui-state-active" href="#">10
    </a>
</td>

我的最终目标是获得 a 标签之间的 10.到目前为止,这是我的代码:

My ultimate goal is to get the 10 that's between the a tags. This is my code so far:

option = selenium.webdriver.ChromeOptions()
option.add_argument(" - incognito")
browser = webdriver.Chrome(executable_path=r"chromedriver.exe")
browser.get(myUrl)
calendar = browser.find_element_by_xpath(
    '/html/body/main/section/div[2]/div[1]/div[2]/div[3]/div/div[1]/div/div[1]/div[2]')
viewCal = browser.find_element_by_name('choice_set[begin_at]')
viewCal.click()

row = calendar.find_elements_by_tag_name('tr')

column = calendar.find_elements_by_tag_name('td')
numb = column[0].find_element_by_tag_name('a')
numb.text

numb.text 返回 '' 而不是 10.

numb.text returns '' instead of 10.

我在这里做错了什么?

推荐答案

尝试使用以下代码:

numb.get_attribute("innerText")

这篇关于Selenium 返回空字符串而不是实际数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆