pragma solidity >= 0.5.0 < 0.6.0;
import "github.com/provable-things/ethereum-api/provableAPI_0.5.sol";
contract YoutubeViews is usingProvable {
string public viewsCount;
event LogYoutubeViewCount(string views);
event LogNewProvableQuery(string description);
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == provable_cbAddress());
viewsCount = _result;
emit LogYoutubeViewCount(viewsCount);
// Do something with viewsCount, like tipping the author if viewsCount > X?
}
function update()
public
payable
{
emit LogNewProvableQuery("Provable query was sent, standing by for the answer...");
provable_query("URL", 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(@class, "watch-view-count")]/text())');
}
constructor()
public
{
update()
}
}
@gwills:[matrix.org](http://matrix.org) probably remix doesn't support github sym link anymore. Try to replace the import string with the following one:
import "github.com/provable-things/ethereum-api/provableAPI_0.5.sol";
This should compile fine
Hi @NazarovALAL, unfortunately YouTube doesn't provide the same HTML code you see when accessing the page through your browser, hence why the xpath clause fails to get the views. This happened to other users before and the code there is a bit out of date for that purpose but still valid as an example if you want to access an HTML through .xpath().
You can do a test by looking for an website where you get the same HTML by other means other than the browser (using curl or wget for example)