在Python中向URL添加参数

2024-10-03 23:20:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在python中为url添加一个参数

     playerNumber = mydict['auctionInfo'][0]['tradeId']
     test = requests.get('https://utas.s2.fut.ea.com/ut/game/fifa16/trade/159826040532/bid', headers=headers, cookies=cookies)

我希望用值playerNumber替换数字159826040532


Tags: httpstesturl参数getrequestsmydictheaders
0条回答
网友
1楼 · 发布于 2024-10-03 23:20:38

您可以使用string.format

test = requests.get('https://utas.s2.fut.ea.com/ut/game/fifa16/trade/{}/bid'.format(playerNumber), headers=headers, cookies=cookies)

或者更清楚地说:

test = requests.get('https://utas.s2.fut.ea.com/ut/game/fifa16/trade/{playerNumber}/bid'.format(playerNumber=playerNumber), headers=headers, cookies=cookies)

相关问题 更多 >