Skip to main content
 首页 » 编程设计

python之伪造一个 cookie 以在 python 中抓取一个站点

2024年08月12日37三少

我要抓取的网站使用 js 创建 cookie。我在想的是,我可以在 python 中创建一个 cookie,然后使用该 cookie 来抓取网站。但是,我不知道这样做的任何方式。有人有什么想法吗?

请您参考如下方法:

请参阅Python httplib2 - Handling Cookies in HTTP Form Posts有关向请求添加 cookie 的示例。

I often need to automate tasks in web based applications. I like to do this at the protocol level by simulating a real user's interactions via HTTP. Python comes with two built-in modules for this: urllib (higher level Web interface) and httplib (lower level HTTP interface).