从URL读取HTML文件 [英] Reading HTML file from URL

查看:165
本文介绍了从URL读取HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然大部分时间我只是使用 file_get_contents 和CURL,但是我无法让它在URL中使用端口。我怎样才能读取这个文件?
http://174.120.124.178:7800/7.html (这是一个shoutcast统计文件)

最后,我只想在最后一个逗号后面显示文本。

解决方案它与港口无关。他们阻止你,因为你没有使用浏览器用户代理。 curl 确实可以让您伪造用户代理,但这可能违反了网站的服务条款。



根据这篇文章,这不是关于阻止脚本,但只是区分Shoutcast客户和其他一切。所以这段代码是:

$ $ $ $ $ codeurl_setopt($ curl_handle,CURLOPT_USERAGENT,Mozilla);


While most of the time I'd just use file_get_contents and CURL, I can't get it to work with a port in the URL. How can I read this file? http://174.120.124.178:7800/7.html (It's a shoutcast statistics file)

Ultimately, I just want the text after the last comma.

解决方案

It has nothing to do with the port. They're blocking you because you're not using a browser user agent. curl does let you fake the user agent, but that may be a violation of the site's terms of service.

According to this post it's not about blocking scripts, but just distinguishing between Shoutcast clients and everything else. So the code is:

curl_setopt($curl_handle, CURLOPT_USERAGENT, "Mozilla");

这篇关于从URL读取HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆