简体   繁体   English

如何在谷歌中改变城市与python有关的事情

[英]how to change city in Google things to do with python

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.我想从 Google 的事情中提取数据做https://www.google.com/travel/things-to-do/see-all ,我有多个关键字,但遇到了问题。 I'm not able to put my keyword , because as I understand Google decoding cities in request url like this - "Moscow" to "04swd".我无法输入我的关键字,因为据我了解,谷歌在请求网址中解码城市 - “莫斯科”到“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正如您在屏幕截图中看到的那样,出了点问题

在此处输入图像描述

You have to use javascript to force the value of the input box to change你必须使用javascript来强制改变输入框的值

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM