简体   繁体   English

Scrapy:在没有蜘蛛的情况下以脚本方式发送帖子

[英]Scrapy: send post in script way without Spider

#!/usr/bin/env python3

import scrapy


def errback(failure):
    print(failure)

def callback(response):
    print(response)


scrapy.FormRequest(r'https://example.com',
                   callback=callback,
                   errback=errback)

In the script above, neither errback nor callback is called.在上面的脚本中,既没有调用 errback 也没有调用回调。

What is the simplest way to send a post request to https://example.com using scrapy in python3.在python3中使用scrapy将post请求发送到https://example.com的最简单方法是什么https://example.com I'd like to avoid using a Spider class/object if possible.如果可能,我想避免使用 Spider 类/对象。

use requests使用requests

pip3 install requests

import requests

url = "[url]"

payload = {}
headers = {
  #Headers here
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM