0

There is a page that contains more than one table. I would like to scrape any table whatever I want.

I have noticed that using the code below I receive only access to the first table:

import requests
import lxml.html as lh

url= 'some url'

page = requests.get(url)

doc = lh.fromstring(page.content)

tr_elements = doc.xpath('//tr')

for t in tr_elements[0]:
    name=t.text_content()
    print(name)

According to the answers included in How can I find an element by CSS class with XPath? i was trying to do the following in order to get access to the other table. I have written

doc.xpath('//*[contains(@class, 'some name of the class')]//tr') instead of just

doc.xpath('//tr'). However this gave me no result. I must admit that my knowledge of using xpath is very low, so I would like to receive an answer instead of just informing me that someone has asked a similar question.

Thank you in advanced for help.

EDIT:

here is the url: https://biznes.interia.pl/gieldy/notowania-gpw/profil-akcji-mab,wId,6852,tab,przebieg-sesji

mkultra
  • 135
  • 3
  • if you don't want to give the url, you should at least give some html that reproduces exactly your problem – diggusbickus Sep 03 '21 at 15:57
  • Ok. I am editing my question in a moment! – mkultra Sep 03 '21 at 16:01
  • FF allows to test xpaths on console over the current page as `$x('//table[@class="sidebar-stats"]//tr')`. In your case it could be something like `doc.xpath('//tr[@class="someName"]')` – LMC Sep 03 '21 at 20:37

0 Answers0