如果用户输入视频的名称,它将链接到该名称最常查看的Youtube视频。例如,如果用户搜索“Sam Smith”,它将重定向到Sam Smith的观看次数最多的视频。我该怎么办?
答案 0 :(得分:1)
您熟悉命令行吗?
如果是这样,这个perl程序会为您提供给定用户观看次数最多的视频的网址。这假设YouTube不会很快改变他们的HTML格式。
#!/usr/bin/perl
print "Enter user name: ";
chomp ($user = <STDIN>);
my $url = "https://www.youtube.com/user/".$user."/videos?sort=p"; # sort=p means sort by popularity
# open the web page
open F, "wget -q -O- $url|" or die "Could not wget $url";
my $mostViewedUrl = 'ERROR';
foreach $line (<F>){
# Since the urls are sorted by popularity,
# we want the first url only.
if($line =~ /.*<h3 class="yt-lockup-title ">/){
$mostViewedUrl = $line;
last;
}
}
$mostViewedUrl =~ s/.*href="([^"]+).*/$1/;
$mostViewedUrl = 'youtube.com'.$mostViewedUrl;
print "Most viewed link: $mostViewedUrl";
答案 1 :(得分:0)