How to make POST request to an API with SCRAPY

Viewed 128

I wanted to know the method which you are using to make a POST request to an API using SCRAPY.

Please bear with me if you think this question is not in standards of Stackoverflow.

Your help is appreciated.

I was scraping a website that shows data with the API but unfortunately, I can't scrape it.

Website: https://www.sla.org.sg/hive/sla/membershipDirectory

enter image description here

1 Answers

You need to yield a FormRequest, the body of the request should go into formdata parameter. Read more here. Something like this:

api_url =  'https://www.sla.org.sg/hive/sla/membershipDirectory/search'
sample_form = {
   'field1': 'value1',
   'field2': 'value2',
}
yield FormRequest(url=api_url, formdata=sample_form, callback=your_parsing_method)
Related