Reading HTML file from URL

若如初见. 提交于 2019-12-11 23:48:39

问题


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.


回答1:


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");



回答2:


I tried to download your file with Curl on the command line and got a 404 error; it does load with Firefox and Lynx. This page says that you need to change the User-Agent string for it to download.




回答3:


CURLOPT_PORT Needs to be set to the appropriate port perhaps~



来源:https://stackoverflow.com/questions/5136712/reading-html-file-from-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!