python post request for list of strings

So I'm trying to send a list of strings line by line via post requests, I'm able to send one string using,

from bs4 import BeautifulSoup
import requests as req
import re

payload={'search': 'example'}

resp = req.post('https://example.com/search.php', data=payload)

print(resp.text)

but rather than just search for " example " i wish to present a list of strings, so example of this -

list = strings.txt

payload={'search': list}

which will then search each string line by line individually for a response. Rather than just that one individual string.

list example -

example1
example2
example3
example4

1 answer

  • answered 2018-01-11 19:58 Usernamenotfound

    You will have to iterate through the list. You can't expect the remote server to handle lists.

    Try this instead

    for i in list:
        payload={'search': i}
        resp = req.post('https://example.com/search.php', data=payload)
        print(resp.text)