0

I'm looking for a little bit of help.

I'm using Selenium Wire to process the requests from a website and I need to change some settings in the requests.

I found the request_interceptor method which work perfectly. Problem is, I can only overwrite a param in the URL, I didn't find a way to delete one.

Let's say for instance, I go to the website : myawesomeweather.com/monday Let's say this url loads an api file called myawesomeweather.com/api/?d=monday&y=2021&m=03 and get all the data for the mondays in march 2021. To avoid doing multiples requests, I just want to modify the request for 2020, so I did this :

def ForceYear(request):
params = request.params
params['y'] = '2020'
request.params = params

driver.request_interceptor = ForceYear
driver.get(WeatherURL)

Which is perfect, I get the url api : myawesomeweather.com/api/?d=monday&y=2020&m=03 But now I'd like to do all of the months for 2020, so i want to remove the &m=03 and only have myawesomeweather.com/api/?d=monday&y=2020

How can I do it ? If I overwrite the &m= and put '', it doesn't work, the setting needs to be completely out of the link..

Thanks !

-- Edit

I should have searched more, basicaly the function just takes every parameters of the url and puts them into a dict, so just have to do this :

    if('m' in params):
          del params['m']

Thanks for your time

Kaka32
  • 1
  • 2

1 Answers1

0

Remove the key from params

params.pop('m', None)
Karl Thornton
  • 1,001
  • 1
  • 2
  • 5