Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python 如何获取“的内容”;id";_Python_Selenium_Python Requests - Fatal编程技术网

Python 如何获取“的内容”;id";

Python 如何获取“的内容”;id";,python,selenium,python-requests,Python,Selenium,Python Requests,我想从这个id中获得2016年,或者从年份中获得“年份” <tr id="2016" Years="year of" style> 我使用的是请求、selenium和phantomJS您可以使用.get_attribute('id')来获取元素中存在的任何属性 year = driver.find_element_by_id("id").get_attribute('id') ## Return ID as string. 您可以在中找到有关从HTML标记获取元素属性的

我想从这个id中获得2016年,或者从年份中获得“年份”

<tr id="2016" Years="year of" style>

我使用的是请求、selenium和phantomJS

您可以使用
.get_attribute('id')
来获取元素中存在的任何属性

year = driver.find_element_by_id("id").get_attribute('id') ## Return ID as string.     
您可以在

中找到有关从HTML标记获取元素属性的更多信息。您可以使用get_属性(“id”)或get_属性(“Years”)分别提取“2016”或“年份”

以下是您可以使用的代码:

year = driver.find_element_by_id("2016").get_attribute("id")


有人知道该怎么办吗?这里有一些类似的东西,我想擦掉。我想获得xxx我如何找到元素:Years find_element_by_id仅适用于id我如何找到元素:Years find_element_by_id仅适用于id
year = driver.find_element_by_id("2016").get_attribute("id")
string = driver.find_element_by_id("2016").get_attribute("Years")