如何在CURL中使用cookie jar时注入cookie? [英] How do I inject cookies when using a cookie jar in CURL?

查看:171
本文介绍了如何在CURL中使用cookie jar时注入cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用php curl,我使用cookie jar进行多步爬行。我需要从服务器动态生成的Cookie。



但是在某一步,一些cookie是使用javascript生成的。因为curl不运行javascript我需要注入cookie来卷曲这一点。



我可以看到这样做的唯一方法是手动读取cookie文件,并设置所有的cookies加上我想使用 curl_Setopt CURLOPT_COOKIE


$ b $

解决方案

我发现如果你使用cookie jar和 curl_setopt wit CURLOPT_COOKIE 它不会覆盖从文件加载的cookie,它只是追加它们。



因此,答案是使用 CURLOPT_COOKIE



感谢Byron!


I am using php curl and i am using the cookie jar for a multi-step crawl. I need the dynamically generated cookies from the server.

But at one step some cookies are generated using javascript. Since curl doesn't run javascript I need to inject cookies to curl at this point.

The only way I can see doing this is manually reading the cookie file, and setting all the cookies plus the ones I want using curl_Setopt and CURLOPT_COOKIE.

Is there a way to inject cookies without loosing the ones already there?

解决方案

I found if you use the cookie jar, and curl_setopt wit CURLOPT_COOKIE it doesn't overwrite the cookies it loaded from the file, it just appends them.

So the answer is to use CURLOPT_COOKIE.

Thanks Byron!

这篇关于如何在CURL中使用cookie jar时注入cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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