有了美剧还怕假期剧荒吗?
马上放小长假了,最近疫情又开始反复,出门游玩也是到处都比较堵,时间也比较仓促,肯定有很多的小伙伴就选择宅在家里了吧。那么身为宅男宅女怎么可能不追剧呢?特别是我追剧可是冒着秃头的危险在进行。最近小编迷上了美剧,无奈好多网站的美剧质量内容都参差不齐,于是乎我就想着自己动手啦,用python爬美剧去。
简单的写了个爬虫,抓取目标网站上所有美剧链接,并保存在文本文档中,想要哪部剧就直接打开复制链接到迅雷就可以下载啦。
数据来源于:https://www.ttmeiju.org/
以下就是上述需求的实现代码。
<?php
// 要访问的目标页面
$url = "https://www.ttmeiju.org/";
$urls = "https://www.ttmeiju.org/";
// 代理服务器(产品官网 www.16yun.cn)
define("PROXY_SERVER", "tcp://t.16yun.cn:31111");
// 代理身份信息
define("PROXY_USER", "username");
define("PROXY_PASS", "password");
$proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);
// 设置 Proxy tunnel
$tunnel = rand(1,10000);
$headers = implode("\r\n", [
"Proxy-Authorization: Basic {$proxyAuth}",
"Proxy-Tunnel: ${tunnel}",
]);
$sniServer = parse_url($urls, PHP_URL_HOST);
$options = [
"http" => [
"proxy" => PROXY_SERVER,
"header" => $headers,
"method" => "GET",
'request_fulluri' => true,
],
'ssl' => array(
'SNI_enabled' => true, // Disable SNI for https over http proxies
'SNI_server_name' => $sniServer
)
];
print($url);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
// 访问 HTTPS 页面
print($urls);
$context = stream_context_create($options);
$result = file_get_contents($urls, false, $context);
var_dump($result);
?>一开始以为2万多部需要很多时间,但是其实也就花了几十分钟而已,难道是因为我挂了高质量代理的原因?所以一路畅通无阻,哈哈,有了这些美剧假期就不无聊啦。
有了美剧还怕假期剧荒吗?
xiaotaomi
会员积分:7320
马上放小长假了,最近疫情又开始反复,出门游玩也是到处都比较堵,时间也比较仓促,肯定有很多的小伙伴就选择宅在家里了吧。那么身为宅男宅女怎么可能不追剧呢?特别是我追剧可是冒着秃头的危险在进行。最近小编迷上了美剧,无奈好多网站的美剧质量内容都参差不齐,于是乎我就想着自己动手啦,用python爬美剧去。
简单的写了个爬虫,抓取目标网站上所有美剧链接,并保存在文本文档中,想要哪部剧就直接打开复制链接到迅雷就可以下载啦。
数据来源于:https://www.ttmeiju.org/
以下就是上述需求的实现代码。
<?php
// 要访问的目标页面
$url = "https://www.ttmeiju.org/";
$urls = "https://www.ttmeiju.org/";
// 代理服务器(产品官网 www.16yun.cn)
define("PROXY_SERVER", "tcp://t.16yun.cn:31111");
// 代理身份信息
define("PROXY_USER", "username");
define("PROXY_PASS", "password");
$proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);
// 设置 Proxy tunnel
$tunnel = rand(1,10000);
$headers = implode("\r\n", [
"Proxy-Authorization: Basic {$proxyAuth}",
"Proxy-Tunnel: ${tunnel}",
]);
$sniServer = parse_url($urls, PHP_URL_HOST);
$options = [
"http" => [
"proxy" => PROXY_SERVER,
"header" => $headers,
"method" => "GET",
'request_fulluri' => true,
],
'ssl' => array(
'SNI_enabled' => true, // Disable SNI for https over http proxies
'SNI_server_name' => $sniServer
)
];
print($url);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
// 访问 HTTPS 页面
print($urls);
$context = stream_context_create($options);
$result = file_get_contents($urls, false, $context);
var_dump($result);
?>一开始以为2万多部需要很多时间,但是其实也就花了几十分钟而已,难道是因为我挂了高质量代理的原因?所以一路畅通无阻,哈哈,有了这些美剧假期就不无聊啦。

21-09-18 16:05

1088

0
回复
暂无评论