Answer the question
In order to leave comments, you need to log in
Data Not Found. Python + XPath. What is the problem?
Good afternoon. I parse one famous torrent tracker to make a more convenient catalog of music by genre. And here's the problem. Everything is fine under the debugger. The data is located. But outside the debugger, at the first attempt to parse the text, the Xpath not found error occurs. Initially, I used xpath_list, then I had to narrow down the selection criteria and switch to xpath_text.
Here is a piece of code:
for q, i in enumerate(g.xpath_list('//tr[@class="hl-tr"]//a[@class="torTopic bold tt-text"]')):
# получаем ссылки на активные ветки
hrefs.append(i.get('href'))
# достаем из ссылки id топика
id = re.search(r'\d+', hrefs[q]).group()
# получаем количество закачек торрента по его id
down_count_temp = g.xpath_text('//tr[@id="tr-' + id + '"]//p[@class="med"]/b')
Answer the question
In order to leave comments, you need to log in
I can assume that you are using grablib. Sites are changeable, that is, you can rarely be 100% sure that at a certain moment that this or that element will be on the page.
In the debugger, you check on a "known" page, and as soon as the parser reaches a "live" page where the element is missing, it throws an exception.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question