socket 实例
用file_get_contents获取远程文件,返回错误,连接不上。网上有人说可以用socket。没用过啊,搜了一下都是你转我的我转你的,对于初次接触的人来说可操作性不强啊。
我现在的需求是写小偷程序,从别人的网站上拷内容。
那些介绍socket的文章都有提到“服务端程序”和“客户端程序”。
我有个不明白的地方:
服务端程序是放在哪儿的?被访问网站的服务器上吗? 那跟我应该没关系吧(不用写),我是不是只需要写客户端程序呢?
实例拜托硬编码 就以www.baidu.com为例子吧 感谢感谢!!
回复讨论(解决方案)
socket 不是分放在哪,而是监听一方为服务器端,请求连接一方为客户端
你如果只是要抓东西,socket对你来说太难了,没必要,用curl吧,搜索一下本版,相关帖子多的是
file_get_contents 不行吗,出了什么错。
file_get_contents 不行吗,出了什么错。
由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败
对方做了限制吧,尝试着用curl试试看。
socket 不是分放在哪,而是监听一方为服务器端,请求连接一方为客户端
你如果只是要抓东西,socket对你来说太难了,没必要,用curl吧,搜索一下本版,相关帖子多的是
要是能用也不用想socket的办法了
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, "http://bbs.csdn.net/topics/380240079");
curl_setopt($ch, CURLOPT_HEADER, 0);
// 抓取URL并把它传递给浏览器
var_dump(curl_exec($ch));
// 关闭cURL资源,并且释放系统资源
curl_close($ch);
换了n个链接,都返回false。 发给朋友试,他说他那边返回true
不是可以吗,你那里不可以吗
不是可以吗,你那里不可以吗
这是我试的代码:
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, "http://bbs.csdn.net/topics/380240079");
curl_setopt($ch, CURLOPT_HEADER, 0);
// 抓取URL并把它传递给浏览器
var_dump(curl_exec($ch));
// 关闭cURL资源,并且释放系统资源
curl_close($ch);
不行。
兄弟帮忙试试看?
通过curl抓取网页。
用你的代码可以出来啊
用你的代码可以出来啊
昨天回家试可以。怪了
找到一个,试试:
function read_file($url){ $r=@file_get_contents($url); if(!$r){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //设置访问的url地址 //curl_setopt($ch,CURLOPT_HEADER,1); //是否显示头部信息 curl_setopt($ch, CURLOPT_TIMEOUT, 5); //设置超时 curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_); //用户访问代理 User-Agent curl_setopt($ch, CURLOPT_REFERER,_REFERER_); //设置 referer curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); //跟踪301 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回结果 $r = curl_exec($ch); curl_close($ch); } return $r; }
不行就表示你的 curl 扩展没有开启,不过连 file_get_contents 都不能访问 url 的话,curl 多半是不黑开启的
不行就表示你的 curl 扩展没有开启,不过连 file_get_contents 都不能访问 url 的话,curl 多半是不黑开启的
扩展开启了
我在公司试,不管用file_get_contents ,curl都不行。回家试可以。 不知道跟网络有没有关系?

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor