Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 重新登录到已删除的网站以恢复一个已删除的工作_Python_Scrapy - Fatal编程技术网

Python 重新登录到已删除的网站以恢复一个已删除的工作

Python 重新登录到已删除的网站以恢复一个已删除的工作,python,scrapy,Python,Scrapy,有没有办法让爬行器在恢复先前暂停的刮片作业时登录到网站 编辑:澄清一下,我的问题其实是关于刮擦蜘蛛,而不是一般的饼干。也许更好的问题是,当一个被冻结在作业目录中的爬行动物复活时,是否有任何方法被调用。是的,您可以 您应该更清楚地了解刮板的确切工作流程 不管怎样,我假设您将在第一次抓取时登录,并希望在恢复抓取时使用相同的cookie 你可以利用图书馆做类似的事情。这是他们的代码示例,为了更清晰,我添加了注释 import urllib import httplib2 http = httplib

有没有办法让爬行器在恢复先前暂停的刮片作业时登录到网站

编辑:澄清一下,我的问题其实是关于刮擦蜘蛛,而不是一般的饼干。也许更好的问题是,当一个被冻结在作业目录中的爬行动物复活时,是否有任何方法被调用。

是的,您可以

您应该更清楚地了解刮板的确切工作流程

不管怎样,我假设您将在第一次抓取时登录,并希望在恢复抓取时使用相同的cookie

你可以利用图书馆做类似的事情。这是他们的代码示例,为了更清晰,我添加了注释

import urllib
import httplib2

http = httplib2.Http()

url = 'http://www.example.com/login'   
body = {'USERNAME': 'foo', 'PASSWORD': 'bar'}
headers = {'Content-type': 'application/x-www-form-urlencoded'}

//submitting form data for logging into the website
response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))

//Now the 'response' object contains the cookie the website sends
//which can be used for visiting the website again

//setting the cookie for the new 'headers'
headers_2 = {'Cookie': response['set-cookie']}

url = 'http://www.example.com/home'   

// using the 'headers_2' object to visit the website,
response, content = http.request(url, 'GET', headers=headers_2)

如果您不清楚cookies是如何工作的,请执行以下操作。简而言之,“Cookies”是一种客户端技术,可以帮助服务器维护会话。

Oops,我错过了“Scrapy spider”部分。这将与一个简单的抓取脚本有关。感谢superxor的提示!正如你所说的,我的问题是关于刮痧的。我将编辑原稿以澄清这一点。