1

I want to scrape quick answer box of google(e.g., the selected text):

1

I've checked other questions asked on the website regarding the same but that didn't help. How can I do that ?

  • Does this answer your question? [Google Search Web Scraping with Python](https://stackoverflow.com/questions/38619478/google-search-web-scraping-with-python) – lionking-123 Aug 30 '21 at 09:43

1 Answers1

1

I think this might help you , have given gold rate in search

import requests
from bs4 import BeautifulSoup

headers = {
    'User-agent':
    "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"
}

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)
soup = BeautifulSoup(r.text, 'lxml')

result = soup.find('div', class_='vlzY6d')
print(result.text)
  • It's returning **None**. And showing _Import "lxml" could not be resolved_ as a problem... – Ashutosh Singh Aug 30 '21 at 10:07
  • works fine for me have added import can u try it with this ? if ur trying on vscode add this in vscode setting json "python.analysis.extraPaths": ["./path-to-code/"], –  Aug 30 '21 at 10:09
  • tried this still it's returning "None" :( – Ashutosh Singh Aug 30 '21 at 10:42
  • ohk can u try after pip install lxml –  Aug 30 '21 at 10:51
  • 1
    Thank you so much... Uninstalled and installed lxml again and it's working now :) – Ashutosh Singh Aug 30 '21 at 11:39
  • wanted to ask one more question. I am facing issue while scraping this HTML below : – Ashutosh Singh Aug 30 '21 at 11:43
  • the abstract science of number, quantity, and space, either as abstract concepts ( pure mathematics ), or as applied to other disciplines such as physics and engineering ( applied mathematics ).
    "a taste for mathematics"
    – Ashutosh Singh Aug 30 '21 at 11:43
  • I tried writing like this `result = soup.find('div', class_= 'LTKOO sY7ric') print(result.span.text) speak(result.span.text)` – Ashutosh Singh Aug 30 '21 at 11:45
  • Facing this issue: `You: what is the meaning of mathematics Traceback (most recent call last): File "c:\MY Programmes\DUSTIN- THE VOICE ASSISTANT\dustin.py", line 106, in print(result.span.text) AttributeError: 'NoneType' object has no attribute 'span'` – Ashutosh Singh Aug 30 '21 at 11:47
  • can u ping exactly where uyou are trying to scrape –  Aug 30 '21 at 11:48
  • just try with result.text –  Aug 30 '21 at 11:52