1

I want to get 2016 out of this id or the "year of" out of Years.

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

I want to scrape the 2016, how would I do this? considering there is multiple "id" on the page? I have tried:

year = driver.find_element_by_id("id")

i am using requests, selenium and phantomJS

KingPey
  • 29
  • 6
  • Anybody have any idea what to do? Here's something similar I want to scrape. – KingPey Nov 26 '16 at 00:11

2 Answers2

1

You can use .get_attribute('id') to get any attributes present in the element.

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

You can find more information about getting element attributes from HTML tags in the Webdriver docs

Prabhakar
  • 1,138
  • 2
  • 14
  • 30
Aitor Martin
  • 724
  • 1
  • 11
  • 26
1

You can use get_attribute("id") or get_attribute("Years") to extract "2016" or "year of" respectively.

Below is the code you can use :

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

or

string = driver.find_element_by_id("2016").get_attribute("Years")
Vijay
  • 96
  • 3