2
I got it with the help of @Qmechanic73
, make a parser on a remote site, and capture the values between the tags span that is within several div with his determined id, and the span with their class and values between their tags, had to capture and decrease the original values in -20%, the code looked exactly like this:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$html = file_get_contents('https://pt.sportingbet.com/services/InPlayApp.mvc/GetInPlaySports?CurrentOddsFormat=', false, $context);
$DOM = new DOMDocument();
$DOM->loadHTML($html);
$xpath = new DomXpath($DOM);
$prices = $xpath->query('//*[contains(concat(" ", normalize-space(@class), " "), "priceText ")]');
$percent = 20.0 / 100.0; // 20%
foreach($prices as $price){
$value = $price->nodeValue;
$floatValue = floatval($value);
$finalValue = $floatValue - ($percent * $floatValue);
$price->nodeValue = $finalValue; // Salva o valor final com desconto de 20%
}
echo $DOM->saveHTML();
Okay, it all worked out cute and according to what I wanted, but then I saw that for the site to recover this information I need to change more than the values of span, need to change values between 2 fields input.
HTML
<div id="isOffered">
<a class="price " href="javascript:;">
<span class="priceText wide UK">1/4</span>
<span class="priceText wide EU">1.25</span>
<span class="priceText wide US">-400</span>
<span class="priceText wide CH">1.25</span>
<span class="priceChangeArrow" ></span>
<input type="hidden" class="betCode" value="0]SK@84899932@323698807@NB*1~4*0*-1*0*0"/>
<input type="hidden" class="decValue" value="1.25"/>
<input type="hidden" class="originalBetCode" value="0]SK@84899932@323698807@NB*1~4*0*-1*0*0"/>
</a>
</div>
<div class="market-item ">
<div class="outright-label">Empate</div>
<div class="outright-odds" title="Vencedor do Encontro">
<div id="s_323698809" class="odds draw"> <div id="isNotOffered" class="hide">
<span class="price priceReadonly"></span>
</div>
<div id="isOffered">
<a class="price " href="javascript:;">
<span class="priceText wide UK">3/1</span>
<span class="priceText wide EU">4.00</span>
<span class="priceText wide US">+300</span>
<span class="priceText wide CH">4.00</span>
<span class="priceChangeArrow" ></span>
<input type="hidden" class="betCode" value="0]SK@84899932@323698809@NB*3~1*0*-1*0*0"/>
<input type="hidden" class="decValue" value="4.00"/>
<input type="hidden" class="originalBetCode" value="0]SK@84899932@323698809@NB*3~1*0*-1*0*0"/>
</a>
</div></div>
</div>
</div>
The fields that need changing are the input of class= "decValue" and class= "betCode" and if possible also the class = "originalBetCode". The field input with the class of decValue is simpler because we just need to decrease in 20% as in the fields span.
But I want to turn my attention to input with the class = "BetCode" and originalBetCode, because I will need to change only the 2 numbers that are between ~, and to do this I will need to follow a esquema of calculations that will be like this:
I will have to capture every value obtained in span priceText EU already with the decrease of 20%, that is, if on the remote site the value is 2.30, the Qmechanic73 script will decrease in 20% as desired, then our value will remain 2.30 - 20% = 1.84, now I’ll have to take this 1.84 and decrease 1 from him, (I explain why in front), after decreasing this 1.84 for 1, I’ll have to catch the result 0.84 and multiply by a value fixed, which can be any number, I will then use the 5, then *0.84 * 5* shall be equal to 4.2, what will we do with this value? simple! send it to replace those two numbers in the field BetCode, only in the following way; if for example our code is value="0]SK@84899932@323698807@NB*1~4*0*-1*0*0" we will replace the 1 who is after the @NB by our multiplied value, which in this case is 4.2, and the 4 who is after the ~ is the divider, so if our multiplier always be 5, our divisor also will be, then we will replace the 1~4 for 4.2~5, why then we will get the result of 0.84, then this script will automatically add +1 in all the results obtained by our division!
If we want the value to be 3.2, we’ll have to narrow it down by 1, and multiply the 2.2 for 5 for example, and the result obtained 11 be sent to BetCode as follows:
11~5, 11 is the total value, divided by 5 who is our multiplier +1 automatic of the original script.
So I want to do this by adapting the @Qmechanic73 script, sorry for the long explanation, but I wanted a little help on how to do that! anyone have any idea? and if possible, a limiter, so that if a value decreased in 20% give only pennies, it returns the value 1.00 for example; the original value is 1.20, if I decrease in 20% he would stay 0.96, what would go wrong, then PHP would analyze the numbers that came under 1.00 and raise him to 1.00.
I know it’s long, it’s boring, but I really need your help. Thanks in advance guys
This is just a warning generated by PHP. Current code does not work?
– André Ribeiro
It doesn’t work! it only works when you have a single div, since when there are many it generates this warning and does not return me anything.
– Cassiano José
@Cassianojosé I did something partial here but I have a question: what value do you want to take initially? the value of
decValueor the value ofpriceText wide UK? in the question you mention that you want to decrease by 20% the value of both, which of the two enters the calculation operation?– stderr
@Qmechanic73, is from the field
priceText wide EU, I made a mistake, but I edited it now.priceText wide UKalways contains the same value as inbetcode, type: if indivhas1/4in thepriceText UK, that means that in thebetcodewill have1~4, was even trying to use the value obtained in theUK, replace the bar with~, and do the search on betcode, but I didn’t get much. has PHP functions that I haven’t studied yet, there makes it difficult :(. but I hope it helps me do rs =D– Cassiano José