I'd like the equivalent of an "I'm Feeling Lucky" button, that opens the first result on a google search. Is that possible to do? If so, could somebody help me out? I know it seems like I'm just trying to get you to do my work for me on these last two things I've asked about, but I'm just doing this to learn by example. Thanks guys.(:
13 replies to this topic
#1
Posted 07 October 2011 - 05:17 AM
|
|
|
#2
Posted 07 October 2011 - 05:57 AM
I'm guessing this is the next step of your other project.
Google have an advantage on this, he has the data, so he don't have to display them and redirect after.
Once again, there is 2 way to do so, php and javascript.
In php, you can load the google page (on the server side), and find the url, and after redirect.
In javascript, you load the page, and emulate the click on the first link.
On both case, you have to watch for not clicking on the ads, but really the first link.
This is starting to be a little bit complex, and might take some time to build something like this. Are you really gonna save time with this? More saved time that it will take you to build this script?
Google have an advantage on this, he has the data, so he don't have to display them and redirect after.
Once again, there is 2 way to do so, php and javascript.
In php, you can load the google page (on the server side), and find the url, and after redirect.
In javascript, you load the page, and emulate the click on the first link.
On both case, you have to watch for not clicking on the ads, but really the first link.
This is starting to be a little bit complex, and might take some time to build something like this. Are you really gonna save time with this? More saved time that it will take you to build this script?
#3
Posted 07 October 2011 - 06:17 AM
My main point for wanting this feature is aesthetics. My script, in all the tests done by me and several friends, has functioned perfectly on all occasions (thanks to you). Not only has it done what it's supposed to, it provides the results I was looking for. Now I'd like to be able to grab the first google result and simply display that. Although, would it be possible to click the first link with a certain term in the URL? That would make it more likely to not click on an ad, but the actual webpage.
#4
Posted 07 October 2011 - 06:31 AM
I guess the easiest way (that would not be so easy) would be to use php
You can use the function file_get_contents() with the url as the parameter to load the html file
And than use function like substr, strpos, strstr, or regular expression to strip everything that you don't want
And than you'll have the url of the first link, and after that simply redirect like in the other thread with this new url.
Maybe you could find some script that already do this.
And don't forget, this will work if the html code is like when you test it, so if google ever change the html output (and they do it often) you'll have to redo your script from scratch (almost from scratch)
You can use the function file_get_contents() with the url as the parameter to load the html file
And than use function like substr, strpos, strstr, or regular expression to strip everything that you don't want
And than you'll have the url of the first link, and after that simply redirect like in the other thread with this new url.
Maybe you could find some script that already do this.
And don't forget, this will work if the html code is like when you test it, so if google ever change the html output (and they do it often) you'll have to redo your script from scratch (almost from scratch)
#5
Posted 07 October 2011 - 08:32 AM
So essentially, I use file_get_contents(), refer to the url I defined in my last project.. But then do I really have to STRIP everything, or can I just GET a specific part of it? The nature of this will generally cause the one result needed to have specific keywords in the search result. Could I isolate just a specific piece of it, and take its url like that without stripping it all?
#6
Posted 07 October 2011 - 09:23 AM
Well, the way to get a specific part of it, is to strip everything else.
Maybe with some regular expression you could do it, but I'm not too good with this.
One other thing, some hoster don't allow you to load external website, so you may be limited there
Maybe with some regular expression you could do it, but I'm not too good with this.
One other thing, some hoster don't allow you to load external website, so you may be limited there
#7
Posted 07 October 2011 - 11:20 AM
Could you give me an example of how I might go about doing this? I'm lost.
#8
Posted 07 October 2011 - 11:49 AM
Sorry, to do something like this reprensent a lots of time, and I simply don't have that time.
You'll gonna have to do it yourself
You'll gonna have to do it yourself
#9
Posted 07 October 2011 - 12:04 PM
Well, I understand the concept of pulling the entire page. I just don't understand what to do to strip it down. After that, I can figure it all out myself. I'll try to figure it out anyway, thanks though for all your help. I really, really appreciate all you've helped me out with.
#10
Posted 08 October 2011 - 07:38 AM
Bump. Can anybody help me figure out how to strip certain information pulled with file_get_contents? After that, I can figure out how to determine where to stop cutting on my own. I just need to know how to do it.
#11
Posted 08 October 2011 - 07:52 AM
Well, you load the html of the result page from google.
Inside the html, you will have the link that you want.
You simply need to find a way to only get the link that you want.
Try removing by pattern, or via some id, or specifics keywords. Like I said, it will probably be some how pretty complex to do so...
Inside the html, you will have the link that you want.
You simply need to find a way to only get the link that you want.
Try removing by pattern, or via some id, or specifics keywords. Like I said, it will probably be some how pretty complex to do so...
#12
Posted 09 October 2011 - 10:52 AM
I can figure out how to get them removed, that's not what I'm asking about. I'm asking, how do I even go about removing content in the first place?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









