Timo Cengiz
Timo Cengiz

Reputation: 3417

getting data from specific table/website using XPATH

im trying to use xpath to get some values from a website. http://irvingmasjid.org/index.php

If you look to the top right corner should be a table there with some values. What i want to get is the 6 numbered values below the title "Adhan" meaning:

4.39, 6.20 etc..

I know that you need to find something unique in the html code and i found this:

//*[@id='slideshow-305-57546dc930cff']

but i have no idea on how to move on from there to get to the values that i want. I am trying something like this:

dict = {}

url = "http://irvingmasjid.org/index.php"

rows_xpath = XPath("//*[@id='slideshow-305-57546dc930cff']/")


for id,row in enumerate(blabla:::)
    get the values here... 

Never used much python also xpath so sorry for not being able to provide more information. Please if you have code example it would be appreciated.

Upvotes: 1

Views: 40

Answers (2)

alecxe
alecxe

Reputation: 474181

What is interesting about this case is that you don't even need to parse HTML - the data you are up to is being retrieved from a different URL:

>>> from pprint import pprint
>>> import requests
>>> 
>>> url = "http://irvingmasjid.org/salah2016.php"
>>> response = requests.get(url)
>>> 
>>> pprint(response.json())
{u'_day_of_year': u'157',
 u'adhan_asr': u'5:09',
 u'adhan_dhuhr': u'1:29',
 u'adhan_fajr': u'4:39',
 u'adhan_isha': u'9:49',
 u'adhan_maghrib': u'8:37',
 u'day': u'12:37',
 u'j_asr': u'6:00',
 u'j_dhuhr': u'1:45',
 u'j_fajr': u'5:15',
 u'j_isha': u'10:15',
 u'jumuah_1': u'1:45',
 u'jumuah_2': u'2:45',
 u'midnight': u'12:37',
 u'month_date': u'12:37',
 u'sunrise': u'6:20',
 u'tahajjud': u'1:57'}

Upvotes: 1

R Moyer
R Moyer

Reputation: 1703

In Google Chrome, if you inspect an element, then right-click on it and choose "Copy > Copy XPath" it should generate the xpath you need. See this picture

I'm not sure where you got that id value from, unless it changes periodically. Currently the value for that div's id is slideshow-305-575473207d5b6.

EDIT: Okay, yes it looks like this div's id is randomly generated (refresh the page a few times...should be different every time). So it'd be no use using this as your starting point. May as well go straight to the td elements, since they have their own id.

Upvotes: 0

Related Questions