V
V
Vladislav Vasiliev2016-03-22 11:45:07
PHP
Vladislav Vasiliev, 2016-03-22 11:45:07

How to parse the number of downloads from Yandex Disk?

Hello! I'm trying to parse the number of downloads of a file from a Yandex disk using a link using Simple Html Dom and Xpath, but no data is returned in my xpath.
The code:

//Подключаю simple html dom
  	include('simple_html_dom.php');
    //Исходный сайт
  	$content = file_get_html('https://yadi.sk/d/KFWd3TJJpdi9W');
    //xpath
  	foreach ($content->find('//*[@id="nb-1"]/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/div[2]/div[4]/span[2]') as $link) {
    	echo $link;
  	}

I need to get the value stored in this element:
<span class="item-details__content">7 раз</span>
For completeness, the same element, but with a DIV:
<div class="item-details">
  <span class="item-details__name">Скачан:</span> 
  <span class="item-details__content">7 раз</span>
</div>

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
seriogja, 2016-03-22
@seriogja

Good afternoon!
If you're using composer, you might want to use DomCrawler, which allows you to select css selectors. Which is nicer than xpath in my opinion. If you want to continue on simple_html_dom, you can put an extension on firebug - firepath, which will generate xpath for you. There is an XPath Helper for chrome that does the same thing, but I haven't tried using it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question