I want to scrape quick answer box of google(e.g., the selected text):
I’ve checked other questions asked on the website regarding the same but that didn’t help. How can I do that ?
Advertisement
Answer
I think this might help you , have given gold rate in search
JavaScript
x
14
14
1
import requests
2
from bs4 import BeautifulSoup
3
4
headers = {
5
'User-agent':
6
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
7
}
8
9
r = requests.get('https://www.google.com/search?q=gold+rate+india&safe=active&rlz=1C1GCEB_enIN960IN960&ei=9qksYc76FeeS4-EP-8iQ8AY&oq=gold+rate+india&gs_lcp=Cgdnd3Mtd2l6EAMyCAgAEIAEELEDMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIHCAAQsQMQCjIFCAAQgAQyBQgAEIAEMgUIABCABDIHCAAQsQMQCjoHCAAQRxCwAzoKCAAQsAMQQxCLAzoNCAAQsAMQyQMQQxCLAzoQCAAQgAQQsQMQyQMQRhCAAjoKCAAQgAQQsQMQCjoNCAAQgAQQsQMQgwEQCjoLCAAQgAQQsQMQgwE6BQgAELEDOgcIABCABBAKOgsIABCABBCxAxDJAzoFCAAQkgM6CgguEIAEELEDEAo6CAgAELEDEIMBOgoIABCxAxCDARAKOhMILhCxAxCDARDHARDRAxBDEJMCOgcIABCxAxBDOgQIABBDOgYIABAKEEM6CggAELEDEIMBEEM6CQgAEMkDEAoQQzoICAAQsQMQkQI6CAguEIAEELEDOgUIABCRAjoOCAAQsQMQgwEQyQMQkQI6CwgAELEDEMkDEJECSgUIOhIBMUoFCDwSATNKBAhBGABQgytY4oQBYN2GAWgFcAJ4BIABiQiIAYRBkgEQMC43LjEwLjQuNC4wLjEuMZgBAKABAbABAMgBCrgBAsABAQ&sclient=gws-wiz&ved=0ahUKEwjOza2jvNjyAhVnyTgGHXskBG4Q4dUDCA8&uact=5', headers=headers)
10
soup = BeautifulSoup(r.text, 'lxml')
11
12
result = soup.find('div', class_='vlzY6d')
13
print(result.text)
14