How can i do web scraping from google pages?

Viewed 18

I could use some help. I am trying to do scraping with Python from google search by entering the query "alzheimer's" and I would like to take only the articles produced in a certain time frame (Sept. 20-22). Currently with this code I can't select the time period and I don't understand where the results are pulled from. Could you please help me with this?

query = "world alzheimer's day"
search = query.replace(' ', '+')
results = 100
url = (f"https://www.google.com/search?q={search}&num={results}")

requests_results = requests.get(url)
soup_link = BeautifulSoup(requests_results.content, "html.parser")
links = soup_link.find_all("a")
new_link_herf = []
new_title = []

for link in links:
link_href = link.get('href')
if "url?q=" in link_href and not "webcache" in link_href:
  title = link.find_all('h3')
  if len(title) > 0:
      f = open("risultati.txt", "a")
      new_link_herf = link.get('href').split("?q=")[1].split("&sa=U")[0]
      new_title = title[0].getText()
      #f.write("%s\n" % new_title )
      f.write("%s\n" % new_link_herf)'
0 Answers
Related