使用cURL和php执行点击和注销网站 [英] perform clicks and logout of website using cURL and php

查看:93
本文介绍了使用cURL和php执行点击和注销网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cURL登录到网站.自然的问题是如何单击按钮并最终注销.例如,.javascript使用click()函数. php使用什么?感谢您提供线索.

I used cURL to login into a website. The natural question is how to perform clicks on buttons and than eventually logout. For example..javascript uses click() function. What does php use? Thanks for clues.

我正在关注有关网络抓取的书.作者在其中登录其发布者网站.这本书是旧的并且过时了.更重要的是,它并没有说出注销的信息.这是发布者: https://www.packtpub.com/

I am following the book on web scraping. In it the author logins into it's publishers website. The book is old and out of date. More over, it says nothing about logging out. This is the publisher: https://www.packtpub.com/

推荐答案

单独使用PHP不能click按钮. PHP不能那样工作. PHP可以下载网页的HTML,但无法执行浏览器所能执行的操作.

You can't click a button using PHP alone. PHP doesn't work like that. PHP can download the HTML of a webpage, but it can't perform actions like a browser can.

如果要这样做,将需要一个无头浏览器.无头浏览器通常被视为不可见的浏览器.您可以执行常规浏览器可以执行的大多数操作.有 PhantomJS CasperJS ,为此.

If you want to do that, you will need a headless browser. A headless browser is typically seen as an invisible browser. You can do most things a regular browser can do. There's PhantomJS, and CasperJS, for this.

也有使用PhantomJS的PHP库.例如 PHP PhantomJS .就个人而言,我从未使用PHP做到这一点,但是我确实定期使用PhantomJS和CasperJS.

There are also PHP libraries that use PhantomJS. For example PHP PhantomJS. Personally, I've never done this with PHP, but I do use PhantomJS and CasperJS on a regular basis.

或者,您可以使用PHP来解析链接或按钮的DOM,并复制单击链接/按钮时发出的HTTP请求.

Alternative to that, what you can do with PHP is parse the DOM for links, or buttons, and replicate the HTTP request that's made when clicking the links/buttons.

例如,如果有链接指向/contactus,则只需使用cURL创建对此页面的GET请求.响应将是源代码和/或标题.

For example, if there's a link that goes to /contactus, you simply create a GET request to this page using cURL. The response will be the source code and/or headers.

我目前正在使用CasperJS,PHP和Redis创建一个用于大型社交网络的相当复杂的刮板/自动化/分析工具的项目.

I am currently working on a project that uses CasperJS, PHP and Redis to create a rather complex scraper/automation/analysis tool for a large social network.

请注意,某些网站严重依赖JavaScript,仅使用cURL可能还不够.您可以通过解析JavaScript文件和其他一些高级技巧来解决此问题,但是请相信我,您不想走这条路.这就是为什么我偶尔使用CasperJS的原因.速度较慢,但​​这就是我们目前所拥有的.

As a side note, some sites rely heavily on JavaScript and using cURL may not be enough. You can get around this by parsing the JavaScript file/s, and some other advanced magic, but believe me you do not want to go down this route. Which is why I use CasperJS on occasions. It's slower, but that's all we've got at the moment.

关于注销...删除您的cookie文件.完成.

As for the logging out ... delete your cookies file. Done.

这篇关于使用cURL和php执行点击和注销网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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