全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1086|回复: 22

[疑问] 问个PHP获取网页源代码的问题

[复制链接]
发表于 2024-4-13 15:55:47 | 显示全部楼层 |阅读模式


https://www.ip138.com/iplookup.php?ip=110.242.68.66&&action=2
https://m.ip138.com/iplookup.php?ip=110.242.68.66&&action=2
https://www.ipshudi.com/110.242.68.66.htm

这三个地址,浏览器中都能返回正确的地址信息,但是在php里,无论是使用 file_get_contents()或是curl都会跳转到 https://ipchaxun.com/ 这个页面,但是跳转后的页面源码中却没有任何信息。

请问应该如何去获取到这个页面的一些信息呢?谢谢大家了
发表于 2024-4-13 18:29:58 | 显示全部楼层
这种工具类,要么买接口,要么下免费库自己解析。
不要想着一个curl就白piao,谁也不傻,早都做限制了
发表于 2024-4-13 16:00:59 来自手机 | 显示全部楼层
访问的时候加ua。不加ua会跳转。curl --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" https://www.ip138.com/iplookup.php?ip=110.242.68.66&&action=2
 楼主| 发表于 2024-4-13 16:08:47 | 显示全部楼层
似毛非毛 发表于 2024-4-13 16:00
访问的时候加ua。不加ua会跳转。curl --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537 ...

好的,谢谢您了
 楼主| 发表于 2024-4-13 16:27:40 | 显示全部楼层
似毛非毛 发表于 2024-4-13 16:00
访问的时候加ua。不加ua会跳转。curl --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537 ...
i HTTP/1.1 302 Moved Temporarily Server: nginx Date: Sat, 13 Apr 2024 08:26:28 GMT Content-Type: text/html Content-Length: 138 Connection: keep-alive Location: https://www.ipshudi.com/ x-ws-request-id: 661a41b4_houdxin43_20924-28142
302 Found
nginx


我的提示这个错误
 楼主| 发表于 2024-4-13 17:22:39 | 显示全部楼层
似毛非毛 发表于 2024-4-13 16:00
访问的时候加ua。不加ua会跳转。curl --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537 ...

我在linux下按照您的方法使用可以获取到信息,但是在php里用curl却返回302
发表于 2024-4-13 17:31:45 | 显示全部楼层
说明你ua头没加对呗。又不把代码发出来,都不知道怎么帮你
 楼主| 发表于 2024-4-13 17:33:37 | 显示全部楼层
_leo 发表于 2024-4-13 17:31
说明你ua头没加对呗。又不把代码发出来,都不知道怎么帮你
function curl_ip($url)
{
    $ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}


谢谢您的回复,这是我的代码
 楼主| 发表于 2024-4-13 17:34:47 | 显示全部楼层
_leo 发表于 2024-4-13 17:31
说明你ua头没加对呗。又不把代码发出来,都不知道怎么帮你
function ip_curlGet($url)
{
    $ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    // 输出头
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_FALSESTART, true);
    //模拟常用浏览器的 useragent
    curl_setopt($ch, CURLOPT_USERAGENT, "{$ua}");
    // 不跟随跳转
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;

}


两段都没有效果
发表于 2024-4-13 17:38:21 | 显示全部楼层
前两个连接,我的浏览器是直接404。应该是检查了referer。
 楼主| 发表于 2024-4-13 17:44:06 | 显示全部楼层
icon 发表于 2024-4-13 17:38
前两个连接,我的浏览器是直接404。应该是检查了referer。

我也加过referer,但同样没有效果,它的referer在本地用浏览器看是 2024.ip138.com
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-30 05:52 , Processed in 0.064980 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表