Extracting a link seems easy on regular link by using:
$link = $('a:eq(1)');
var real_link = $link.attr('href');
the hardest part is how to extract link from encrypted link like this:
https://jsfiddle.net/rm7mp8do/
if you hover to the link, on you status bar it will show you fake link like:
hxxp://this_is_fake_link
but after you click it, it will bring you to the original link:
hxxp://mg.com/ghits/xxx/xxx/xxx/xxx/x/x/?h=gdwagdjgawjhvjwhafgdjhwavwxdjhav
You can try this php script using curl return transfer ...
function expand_short_url($url)
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,false);
$header = curl_exec($ch);
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); // Parse information
for($i=0;$i<count($fields);$i++)
{
if(strpos($fields[$i],'Location') !== false)
{
$url = str_replace("Location: ","",$fields[$i]);
}
}
return $url;
}
Related
$mp3Linkger = wp_get_attachment_url($mp3_file_id);
$mp3Link = wp_get_attachment_url($mp3_file_id);
$mp3Link = str_replace( 'example.COM', 'static.example.COM', $mp3Link );
$playerTag = '[audio mp3="'.$mp3Linkger.'"][/audio]';
In the above code
$playerTag loads the link
$mp3Linkger Is broadcast
I want to load $mp3Link if $mp3Linkger was not available
Not available like Down Server or 404 error and ...
Update :
Ways that friends tell / Site loading speed slows down :
function check_url($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $mp3Linkger);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
return $headers['http_code'];
}
$check_url_status = check_url($mp3Linkger);
if ($check_url_status == '200') {
$playerTag = '[audio mp3="'.$mp3Linkger.'"][/audio]';
} else {
$playerTag = '[audio mp3="'.$mp3Link.'"][/audio]'; }
I want this process to happen when the user clicks on the link ($playerTag)
That is, if link a is not available, link b will be loaded
.
You should take a look at #fopen();.
fopen — Opens file or URL
Mode
Description
'r'
Open for reading only; place the file pointer at the beginning of the file.
Source # https://www.php.net/manual/en/function.fopen.php
<?php
/**
* Check if CDN's url is valid, if not return fallback
*/
$test = #fopen( '_Your_CDN_URL_goes_here_', 'r' );
if ( $test !== false ) {
// CDN's url is valid
$url = _Your_CDN_URL_goes_here_;
} else {
// CDN's url isn't valid
$fallback = _Your_fallback_URL_goes_here_;
}; ?>
I access a page via GET (some of its contents are loaded using jquery), on document.ready this page gets saved as a png.
I want to call this page from a command line using inside the command a for loop to save multiple pngs.
How can I do it?
If I run this on the browser it works fine but the idea is not to make it manually, one by one for each gln code.
curl did not work or am I using it wrong?
<script>
#isset($saveCode)
$("#btnPng").click();
#endisset
$("#btnPng").click(function () {
var selected_date = $('#selectReportDate').find(':selected').val() ;
var selected_gln = $('#selectAccount').find(':selected').val() ;
html2canvas($("#printable"), {
onrendered: function (canvas) {
var url = canvas.toDataURL();
$("<a>", {
href: url,
download: selected_date + selected_gln
})
.on("click", function() {$(this).remove()})
.appendTo("body")[0].click()
}
})
});
</script>
command handle code
public function handle()
{
$date = WeeklyTopSheetsData::max('report_date');
$accounts = REF_GA_GLN::Select('gln')->orderBy('account_name')->get();
foreach ($accounts as $account) {
$auxURL = 'http://localhost:8000/topsheet/' . $account['gln'] . '/' . $date . '/1';
$ch = curl_init();
echo $auxURL;
//set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $auxURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
}
echo ' FIN';
}
}
<?php
include_once('simple_html_dom.php');
$veri = file_get_html("http://apps.istanbulsaglik.gov.tr/Eczane");
preg_match_all('#<a href="(.*?)" class="ilce-link" data-value="(.*?)"
data-ilcename="(.*?)" data-title="(.*?)" id="ilce" title="(.*?)"><i
class="fa fa-dot-circle-o"></i>(.*?)</a>#si',$veri,$baslik);
$length = count($baslik[4]);
for ($i = 0; $i < $length; $i++) {
echo $baslik[4][$i];
echo "</br>";
}
preg_match_all('#<table class="table ilce-nobet-detay" id="ilce-nobet-detay">(.*?)</table>#si',$veri,$adres);
echo $adres[1][1];
?>
In this link;
http://apps.istanbulsaglik.gov.tr/Eczane I can not get the right side elements that will be listed under "Eczaneler".
Because I need to click any of left side elements then, I can see them. What I want to do is getting that elements in my web crawler.
The main problem is how can I make my crawler click? without clicking I can not see any data.
If I can make it click, then I can take the data from html source. If not my crawler will always return empty.
If you use any browser's inspector on http://apps.istanbulsaglik.gov.tr/Eczane link, you will see that each link in İlçeler column has a data-value and binded to a click event:
the page Javascript code:
$(function () {
$(".ilce-link").on("click", function (parameters) {
var title = $(this).data("title").toUpperCase();
var id = $(this).data("value");
var request = $.ajax({
url: "/Eczane/nobetci",
method: "POST",
data: { "id": id, "token": "aa416735d12fd44b" },
dataType: "html"
});
request.done(function (data) {
$("#nobet").empty(" ");
$("#nobet").html('<i class="fa fa-spinner fa-spin"></i>');
$("#nobet").html(data);
document.title = "06-11-2017 TARİHİNDEKİ " + title + " İLEÇSİNDEKİ NÖBETÇİ ECZANE LİSTESİ";
});
});
});
This code means that when you click on any link in the left column, the script will create a post request by AJAX to this url: http://apps.istanbulsaglik.gov.tr/Eczane/nobetci with an id and a token.
So the idea is to directly use this url and post data, you can get the id from the link element and the token from the js code on the first page, and then use CURL PHP to post these data.
Here is an example using CURL post:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://apps.istanbulsaglik.gov.tr/Eczane/nobetci");
curl_setopt($ch, CURLOPT_POST, 1);
// you can use preg_match_all to retrieve the id and the token from the first page
curl_setopt($ch, CURLOPT_POSTFIELDS, "id=$id&token=$token");
$output = curl_exec ($ch);
curl_close ($ch);
I´m currently working on a school project, where we are using Apache cordova (HTML, CSS and JS side) and currently our school has a server, where our .php file is located.
In our project, (one of the HTML files) we use API key and an domain address, that we want to get rid off from source code (so other students cant see it). What would be easiest way to execute this?
We´ve been thinking following;
We use the php-file as a wrapper with the following code;
IE.
<?php
function getJson($data){
$decoded = json_decode($data);
if (isset($decoded)){
// Toteutusten haku
$url = "URL THAT WE DONT WANT TO BE SEEN";
$apiKey = "API KEY GOES HERE";
// curl
$ch = curl_init($url);
// curl_exec returnsanswer (not boolean)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Asets api key, ":"
curl_setopt($ch, CURLOPT_USERPWD, $apiKey.":");
// Setting message - JSON
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Sets false if necessary
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Sends request
$responseJson = curl_exec($ch);
return $responseJson;
curl_close($ch); //close session
**}
}
?>
And in HTML file we have code snippets that looks like following;
// B building rooms
if (buildingcode.startsWith("B", 5)) {
var requestB = new XMLHttpRequest();
requestB.onreadystatechange = function () {
if (requestB.readyState === 4) {
if (requestB.status === 200) {
try {
var jsonB = JSON.parse(requestB.responseText);
for (var fb = 0; fb < jsonB.resources.length; fb++) {
var resB = jsonB.resources[fb];
if (resB.type === "room") {
if (bTilat.indexOf("code")) {
bTilat.push(resB.code + resB.name.slice(resB.name.indexOf(' ('), 50));
}
}
}
} catch (e) {
console.log(e.message);
return;
}
}
}
//console.log(bTilat);
};
requestB.open("GET", 'THIS PART HAS THE DOMAIN WE WANT TO HIDE', true, "THIS PART HAS THE API WE WANT TO HIDE", "");
requestB.send(null);
}
So my question is following; I guess we need to get rid off
requestB.open("GET", 'THIS PART HAS THE DOMAIN WE WANT TO HIDE', true, "THIS PART HAS THE API WE WANT TO HIDE", "");
requestB.send(null);
From html, but how do we request the code from wrapper?
Thank you in advance.
I'm trying to develop a tool which gets the links from a page, stores them in an array and opens with one click in a new tab. Is there a way to accomplish that without triggering the browser's popup spam filter?
Here's my code:
<?php
$base = "web.archive.org";
$time = "/web/20160101000000*/";
$domain = #$_POST["domain"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "$base$time$domain");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 20000); //in miliseconds
$output = curl_exec($ch);
curl_close($ch);
# REPLACES ALL URLs OF WAYBACK MACHINE
$replacedHrefHtml = preg_replace('/(href=")/', "href=\"https://web.archive.org", $output);
# REPLACES ALL SRCs OF WAYBACK MACHINE
$replacedsrc = preg_replace('/(src=")/', "src=\"https://web.archive.org", $replacedHrefHtml);
#get wbCalendar
$html = str_get_html($replacedsrc);
$elem = $html->find('div[id=wbCalendar]', 0);
#extract the links and store them into an array
$data = array();
$open = '';
foreach($elem->find('a') as $element) {
$extracted = $element->href;
$open .= "window.open('{$extracted}'); ";
$data[] = $extracted;
}
echo "Open multiple links";
?>
You can test it here: seotify.com/archive-opener
Thanks in advance.
As far as I know there is no way you can ensure the popup filter won't catch you. I think the only thing you can do is to make the windows open in an "on-click" event someElement.onclick = function(){ /*POPUP CODE*/ } (so that the code is triggered in response to a user action)