how to change city in Google things to do with python

Viewed 35

I want to scrap data from Google things to do https://www.google.com/travel/things-to-do/see-all , I have multiple keywords but have faced with problem. I'm not able to put my keyword , because as I understand Google decoding cities in request url like this - "Moscow" to "04swd".

I have also try to use selenium

el = driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz[2]/div/div[2]/div/c-wiz/div[1]/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div[2]/input')
el.send_keys('moscow')

as you can see in screenshots something get wrong

enter image description here

1 Answers

You have to use javascript to force the value of the input box to change

input_txt = 'moscow'
driver.execute_script(f"var box = document.querySelector('input[type=text]'); box.value = '{input_txt}'; box.dispatchEvent(new Event('change'));")
Related