Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用硒';s Python API-如何获取表中的行数?_Python_Selenium - Fatal编程技术网

使用硒';s Python API-如何获取表中的行数?

使用硒';s Python API-如何获取表中的行数?,python,selenium,Python,Selenium,如何使用Selenium的Python API获取HTML表中的行数 我有一个2列的键和值表,我想把它读入字典。比如: browser = Selenium(...) ... rows = ? (this is what I need) for r = range(row): key = browser.get_table('tablename.' + r + '.0') value = browser.get_table('tablename.' + r + '.1')

如何使用Selenium的Python API获取HTML表中的行数

我有一个2列的键和值表,我想把它读入字典。比如:

browser = Selenium(...)
...
rows = ? (this is what I need)
for r = range(row):
    key = browser.get_table('tablename.' + r + '.0')
    value = browser.get_table('tablename.' + r + '.1')
    my_dict[key] = value
谢谢, 司机杰米说:

def get_xpath_count(self,xpath):
    """
    Returns the number of nodes that match the specified xpath, eg. "//table" would give
    the number of tables.

    'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
    """
    return self.get_number("getXpathCount", [xpath,])

以下是我目前的工作:

row = 0
while browser.is_element_present('//tablename//tr[' + str(row+1) + ']/td[1]'):
    key = browser.get_table('tablename.' + str(row) + '.0')
    value = browser.get_table('tablename.' + str(row) + '.1')
    my_dict[key] = value
    row = row + 1
注意,在is_元素中,行和列从1开始,而在get_table()中,行和列从0开始。好的,但是我使用什么xpath呢?“//tablename”给出一个计数,//tabename/tr”给出0个计数。//table[@id=“yourtableid”]/tr