I want to get the bing result without api , I want to get them direct from bing pages using php. I don't know how to do it.
you can use http requests and pares the results to get what you want
you can use regular expressions
example:
$results = file_get_contents("http://www.bing.com/search?q=regular+expressions");
you will find the all HTML content of the page, like you see when click on "view page source"
then apply regex on it to extract the results
Check out this script: http://www.fromzerotoseo.com/scraping-bing-serp/
in particular the regular expression search which grabs the links:
preg_match_all(
'(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU',
$result['EXE'], $matches);
Just use simple_html_dom and do a simple parse. To get # of bing results, you have to find a specific class called "sb_count". If you need links, change the class by "b_attribution" to get all the links.
You can execute your query as follow by looping through the result page using foreach:
include_once 'simple_html_dom.php';
header('Content-Type: text/html; charset=ISO-8859-2');
$html = new simple_html_dom();
$param = 'Your query';
$html -> load_file('https://www.bing.com/search?q=' . $param . '&go=Submit&qs=n&form=QBLH&pq=' . $param . '&sc=8-6&sp=-1&sk=&ghc=1&cvid=e3777d60b1f04c90a3d8f08903433c7a');
foreach ( $html->find('.sb_count') as $post){
echo '<p>' . $post . '</p>';
}
Related
I am having issues testing a rest API. I want to trigger it from PHP by doing a file_get_contents.
This is my code so far
<?php
$url = 'http://domain:0000/rest/createUser?u=username&p=password&username=testuser&password=testpassword&email=user#domain.co.uk&';
$encodedUrl = urlencode($url);
$apicall = file_get_contents($url);
?>
This URL works from a browser, but as soon as I use file_get_contents it doesn't work.
Could the end server be blocking the use of file_get_contents? If so how? and how can I begin to test and troubleshoot this?
The issue is that you're using urlencode.
The urlencode function is used specifically for encoding strings inside a portion of a url. For example, you can use it to add data after the ?, and make sure that things like & turns into %26 and spaces turn into %20.
But it's not used to encode the entire url, it just makes the url invalid.
Try to remove the last "&" in your URL and then use the $encodedUrl instead of $url in the file get contents.
So try to turn this :
$apicall = file_get_contents($url);
INTO
$apicall = file_get_contents($encodedUrl);
I want to edit the priority of a parent object when a child object is added.
I am using PHP and the REST APIs and adding the new child using POST.
But it appears that the .priority setting can only be made using PUT which resets the parent object.
I have read this post and answer:
Push to Firebase via REST API with Priority
but it applies to setting priority for new objects.
Then I tried retrieving the contents of the parent object and resetting it using .value
but that is not working for me - possibly because the object being pushed is a complex one with child objects of it's own.
So is it possible, or will it be possible in the future to PUSH a new .priority setting?
Responding to Andrew as another answer so that I can format the code:
The command you suggest will get me the existing priority but I still do not see how to change the priority. I am using PHP and here is what I have tried:
$url = $urlToParent . '/.priority/.json';
$fields = '{ ".priority" : ' . $timeStamp . ' }';
$result = doSend($url, $fields, 'PUT');
$url = $urlToParent . '/.priority/.json';
$fields = '{ ' . $timeStamp . ' }';
$result = doSend($url, $fields, 'PUT');
$url = $urlToParent . '/.json';
$fields = '{ ".priority" : ' . $timeStamp . ' }';
$result = doSend($url, $fields, 'POST');
doSend() is a PHP function that uses POST or PUT to send data.
These different attempts either delete the entire object, delete the priority setting or return an error. I am sure there must be a way to do what I want, I just haven't hit on the right combination of URL, parameters and sending method.
The simple answer is that you set the priority directly by appending .priority to the end of your URL. ie:
curl https://SampleChat.firebaseIO-demo.com/users/tom/.priority/.json
If you want to set the priority at the same time that other data is written, you can do that as well. See Writing Priorities from the REST API in the docs.
Note that priorities can only be written to locations that already contain data. If you try to write priority to a null location, the priority will be ignored and the REST call will return null.
There is no command that will both push an object and update the parent's priority at the same time (I'm having trouble coming up with a good use case for this -- leave a comment if you have something in mind).
I'm trying to login to a site using following code
my $mech = WWW::Mechanize->new(autosave=>1);
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->follow_link( text => 'Sign In');
$mech->click();
$mech->field(UserName => "$username");
$mech->field(Password => "$password");
$mech->submit();
But during follow_link the href contains two front slashes e.g (//test/sso-login) hence follow_link is considering it as whole URL and it's failing as below
Error GETing http://test/sso-login: Can't connect to test:80 (Bad hostname)
I can't change the href since it's our of my control. Is there a way to overcome this problem and make it take the full URL appending this href.
Sure. You can modify the HTML that Mech is looking at just before you call follow_link():
my $html = $mech->content;
$html =~ s[//test/sso-login][http://example.com/test/sso-login]isg;
$mech->update_html( $html );
See the documentation for details. Search for "update_html" on that page.
I want to display the content from: https://graph.facebook.com/comments/?ids=http://lujanventas.com/test.php in my site.
How can I do it aside from an AJAX call? Can it be done without JS?
you can create a server side script that reads the content of the file and echos it
this is an example for such script in php:
$ids = "http://lujanventas.com/test.php";
$url = "https://graph.facebook.com/comments/?ids=".urlencode($ids);
$data = json_decode(file_get_contents($url),true);
foreach($data[$ids]["comments"]["data"] as $comment){
echo $comment["message"]."<br /><br />";
}
I'm using this code to read the web page content:
my $ua = new LWP::UserAgent;
my $response= $ua->post($url);
if ($response->is_success){
my $content = $response->content;
...
But if $url is pointing to moved page then $response->is_success is returning false. Now how do I get the content of redirected page easily?
You need to chase the redirect itself.
if ($response->is_redirect()) {
$url = $response->header('Location');
# goto try_again
}
You may want to put this in a while loop and use "next" instead of "goto". You may also want to log it, limit the number of redirections you are willing to chase, etc.
[update]
OK I just noticed there is an easier way to do this. From the man page of LWP::UserAgent:
$ua->requests_redirectable
$ua->requests_redirectable( \#requests )
This reads or sets the object's list of request names that
"$ua->redirect_ok(...)" will allow redirection for. By default,
this is "['GET', 'HEAD']", as per RFC 2616. To change to include
'POST', consider:
push #{ $ua->requests_redirectable }, 'POST';
So yeah, maybe just do that. :-)