0

This is the website I want to take data: https://www.wunderground.com/history/daily/gb/london/EGLC/date/2017-2-10. I want to take the Day Average Temp which is 2.7 in this case. When I inspect the element in safari I can copy the row as a HTML,Xpath or Attribute. Since selenium can find elements by Xpath, I choose this method. However, when I copy and paste it in

driver.find_element_by_xpath(//*[@id="inner-content"]/div[2]/div/div[3]/div/div/lib-city-history-summary/div/div[2]/table/tbody[1]/tr[3]/td[1]) 

I get Syntax Error

A picture of the inspection.

If there is another way to select the element with out using an Xpath and that it works I could also use it.Thank you.

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265

2 Answers2

0

The xpath needs to be in quotes, which means you need ot either escape your double quotes:

driver.find_element_by_xpath("//*[@id=\"inner-content\"]/div[2]/div/div[3]/div/div/lib-city-history-summary/div/div[2]/table/tbody[1]/tr[3]/td[1]") 

Or change them to single quotes:

driver.find_element_by_xpath("//*[@id='inner-content']/div[2]/div/div[3]/div/div/lib-city-history-summary/div/div[2]/table/tbody[1]/tr[3]/td[1]") 

or, to more easily use your copy paste, surround your xpath in single quotes:

driver.find_element_by_xpath('//*[@id="inner-content"]/div[2]/div/div[3]/div/div/lib-city-history-summary/div/div[2]/table/tbody[1]/tr[3]/td[1]') 
DMart
  • 2,401
  • 1
  • 14
  • 19
0

That is because it needs to go as a string. Add the quotes as shown in below code

driver.find_element_by_xpath('//*[@id="inner-content"]/div[2]/div/div[3]/div/div/lib-city-history-summary/div/div[2]/table/tbody[1]/tr[3]/td[1]') 
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265