0

I want to include into my python program an option to search for the time in a particular city and to get the google's output on some different things too.

I want to be able to get the google output that appears on the top of the screen(a lot of times it's the output of wikipedia or some other page) by using python code.

For instance:

How would I now copy the 6:10PM output with python?

2
  • 1
    Webscraping is a large topic. Check out BeautifulSoup crummy.com/software/BeautifulSoup/bs4/doc Commented Jun 16, 2020 at 17:31
  • You also have the option of using API to get time of a particular location, check Google's time zone API or search for something similar. Commented Jun 17, 2020 at 6:18

1 Answer 1

1

As shown, the url is timeanddate.com, I capture the location, weekday and time. I don't show the code to read html from web site, if you are interesting, you can get it from below link. You need to have bs4 and brotli installed.

Jason's Tool.py

import brotli
from Tool import read_URL
from bs4 import BeautifulSoup

url = "https://www.timeanddate.com/worldclock/"
response, html = read_URL(url)
if html:
    soup = BeautifulSoup(html, "html.parser")
    tags = soup.find_all('td')
    time_dict = {tags[i].text:tags[i+1].text for i in range(0, len(tags), 2)
        if tags[i].text.strip() != ''}

# a dictionary created with 'location':'weekday hh:mm' key pairs, like
# 'Washington DC *': 'Tue 13:53'

It's better have time_dict as reference, also your system clock. Not to get the time data from web site all the time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.