Iterate through table rows and print column text with Python Selenium

后端 未结 2 1178
我在风中等你
我在风中等你 2020-12-24 07:32

I have a table (

) with values in each row () from its body ().

The value I would lile to p

2条回答
  •  悲&欢浪女
    2020-12-24 08:09

    The XPath you currently using is quite fragile since it depends on the complete document structure and the relative position of the elements. It can easily break in the future.

    Instead, locate the rows using their class or other attributes. For instance:

    for row in driver.find_elements_by_css_selector("tr.GAT4PNUFG.GAT4PNUMG"):
        cell = row.find_elements_by_tag_name("td")[1]
        print(cell.text)
    

提交回复
热议问题