如何在PHP中抓取需要Cookie和JavaScript的页面 [英] How to scrape page requiring cookies and javascript in PHP

查看:127
本文介绍了如何在PHP中抓取需要Cookie和JavaScript的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简便的方法可以使用php脚本抓取需要它的网页脚本来模拟cookie和javascript?

Is there an easy way to emulate cookies and javascript with a php script scraping a web page requiring it?

当前响应显示:

<body><noscript>This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.</noscript></body>

我把它放在代码中,没有什么区别:

I put this in the code and it made no difference:

$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );


推荐答案

<内的HTML; noscript> < / noscript> 仅在禁用Javascript时显示。因此,这是是否启用Javascript的测试。

HTML inside the <noscript> </noscript> will only get displayed if Javascript is disabled. So this is the test for whether Javascript is enabled.

jQuery-cookie-plugin 用于读取,写入和删除cookie。

There is jQuery-cookie-plugin for reading, writing and deleting cookies. But it will not work if Javascript is disabled.

要检查是否已使用PHP代码启用cookie,则需要设置cookie并通过另一个请求读取cookie。 这篇文章上有一些指南。

For checking if cookie is enabled with PHP code, you need to set the cookie and read the cookie with another request. This post have some guides on it.

这篇关于如何在PHP中抓取需要Cookie和JavaScript的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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