首页 \ 问答 \ 使用PHP cURL获取页面内容(Get content of page using PHP cURL)

使用PHP cURL获取页面内容(Get content of page using PHP cURL)

我想使用PHP的cURL访问外部网站上的页面,并获取页面的整个html内容。

当我访问该网站时,它会将我重定向到同一网站上的另一个页面。 此外,我必须设置useragent,我想要一个useragent PC windows7铬和iPhone 4s。 这是我到目前为止所得到的:

$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_AUTOREFERER , true)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$kl = curl_exec ($ch);
curl_close($ch);
echo $kl;

注意:
我可能会遇到更多错误。


I want to use PHP's cURL to visit a page on an external site, and get some the whole html content of the page.

When i visit the site, it will redirect me to another page on the same site. Also, i have to set the useragent, i want a useragent for PC windows7 chrome and iPhone 4s. This is what i got so far:

$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_AUTOREFERER , true)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$kl = curl_exec ($ch);
curl_close($ch);
echo $kl;

Notice:
I will probably run into more errors.


原文:https://stackoverflow.com/questions/17778798
更新时间:2023-06-25 12:06

最满意答案

在MySQL中打开查询日志并监视mysql查询日志文件。

mysqld部分的my.cnf或my.ini文件中添加一个指令:

log = /path/to/my/log/file

Turn on query logging in MySQL and monitor the mysql query log file.

In your my.cnf or my.ini file in the mysqld section add a directive:

log = /path/to/my/log/file

相关问答

更多
  • 我不认为你可以 - 至少不是你所希望的方式。 您将自己构建查询字符串并执行(即不使用语句),或者查找或创建支持该功能的包装器。 我使用的是Zend_Db ,这是我将如何做: $id = 5; $baz = 'shazam'; $select = $db->select()->from('bar','foo') ->where('id = ?', $id) ->where('baz = ?', $baz); // Ze ...
  • 在MySQL中打开查询日志并监视mysql查询日志文件。 在mysqld部分的my.cnf或my.ini文件中添加一个指令: log = /path/to/my/log/file Turn on query logging in MySQL and monitor the mysql query log file. In your my.cnf or my.ini file in the mysqld section add a directive: log = /path/to/my/log/file
  • 所以这是我的建议; 我没有看到您的代码有任何明显错误,但如果不能彻底解决问题,这些步骤应该可以更容易地诊断问题。 首先,将prepare()调用移出循环*。 接下来, 显式创建语句对象 ,这样如果准备有问题,您可以直接从语句对象中获取错误。 最后,在进程的每个阶段检查有效返回,包括参数绑定和语句执行 。 $sql_b = "SELECT fld_title, fld_tag FROM j_oracle_cat WHERE fld_tag IS NOT NULL ORDER BY fld_title"; if ...
  • 代码已经过测试,现在可以使用了 首先创建表并插入记录 create table sectona_product(id int primary key auto_increment, hs varchar(100), nv varchar(80),vsa varchar(86)); insert into sectona_product(hs,nv,vsa) values('jon','gab','secunda');
  • 看起来非常接近。 我添加了两行。 一行存储结果,另一行存储检查以确保您有来自查询的响应。 运行它,看看它是否有帮助。 $sql = "SELECT `username` FROM `usrs` WHERE `username` = ? "; $statement = $this->conn->prepare($sql); if (!statement) { throw new Exception($statement->error); } $statement->bind ...
  • like要求wildcards具有松散的匹配。 例如 select * from table where a like 'b' 是相同的: select * from table where a = 'b' 所以b的记录会被发现,但abc不会。 从手册 : 使用LIKE,您可以在模式中使用以下两个通配符: %匹配任意数量的字符,甚至是零个字符。 _恰好匹配一个字符。 所以要找到abc你会使用: select * from table where a like '%b%' 对于准备好的语句,通配符会附加 ...
  • 我想通了,我终于找到了一个有效的例子,虽然我不得不调整一些部分。 下面的代码将获取从url传递的id,执行预准备语句以更新所选的id,然后重定向到url位置。 唯一缺少的是Limit声明,我还没想出如何开展工作。 该代码也将用于删除几乎相同的一些小调整。
  • 您的PDO配置为模拟准备好的查询,而mysqli使用真正准备的查询。 准备好的查询将字符串''1''绑定为整数参数值。 PHP使用类似intval()东西将它强制转换为整数。 任何带有非数字前导字符的字符串都被PHP解释为0,因此在 prepare 之后发送的参数值是值0。 伪造的查询使用字符串插值 (而不是绑定) 在 MySQL解析之前将字符串''1''添加到SQL查询中。 但结果是类似的,因为SQL还将整数上下文中带有非数字前导字符的字符串视为值0。 唯一的区别是当参数在准备之前与准备之后绑定时,在一般 ...
  • 是和否:有必要再次检查$field变量white-list - 这是防止sql注入的唯一方法 - 但是在$field变量上使用mysqli_real_escape_string是没有意义的。 如果您的列名是保留字或以例如数字开头,则应在反引号中引用它,但就是这样。 您仍然应该为$search变量使用mysqli_real_escape_string准备语句,尽管mysqli_real_escape_string也会这样做(而不是准备好的语句,而不是两者)。 Yes and no: It is necessa ...
  • 您需要绑定完整的值,而不仅仅是它的一部分。 这意味着: $where = "First_Name LIKE ?" 然后绑定: $vals = array('%Mike%'); You need to bind the complete value, not just a portion of it. This means doing: $where = "First_Name LIKE ?" And then binding: $vals = array('%Mike%');

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)