Beverlie
Beverlie

Reputation: 461

How to Send A Consecutive Request by URL : Python-request

I am learning python-request step by step to build a url queries to en.wiktionary.org

I need to build a function that sequentially fetch the url data based on pre-defined key:value dictionary:

Word_Set = {'key1': 'region', 'key2': reason}

If I put something like this:

r = requests.get('http://en.wiktionary.org', params=Word_Set)

What I desire to get is like this:

print(r.url)
http://en.wiktionary.org/region
http://en.wiktionary.org/reason

Any hint how to do this using Python3 and requrests module in it.

Upvotes: 0

Views: 198

Answers (1)

Ken Syme
Ken Syme

Reputation: 3632

You need to make a request per word, you can't do it all in one. Simplest way in this case is to loop over the values in your dictionary:

Word_Set = {'key1': 'region', 'key2': 'reason'}
for word in Word_Set.values():
    r = requests.get('http://en.wiktionary.org/{}'.format(word))
    print(r.url)

Upvotes: 1

Related Questions