Scrapy upload file

半腔热情 提交于 2019-12-29 09:19:10

问题


I am making a form request to a website using scrapy. The form requires to upload a pdf file, How can we do it in Scrapy. I am trying this like -

FormRequest(url,callback=self.parseSearchResponse,method="POST",formdata={'filename':'abc.xyz','file':'path to file/abc.xyz'})

回答1:


At this very moment Scrapy has no built-in support for uploading files.

File uploading via forms in HTTP was specified in RFC1867. According to the spec, an HTTP request with Content-Type: multipart/form-data is required (in your code it would be application/x-www-form-urlencoded).

To achieve file uploading with Scrapy, you would need to:

  1. Get familiar with the basic concepts of HTTP file uploading.
  2. Start with scrapy.Request (instead of FormRequest).
  3. Give it a proper Content-Type header value.
  4. Build the request body yourself.

See also: How does HTTP file upload work?



来源:https://stackoverflow.com/questions/39303851/scrapy-upload-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!