-3

I used beautifulsoup to get data from this website. My code:

import bs4
import requests
from bs4 import BeautifulSoup

r = requests.get('https://www.suncalc.org/#/12.98,80.188,10/2020.02.21/15:51/1/3')
soup = BeautifulSoup(r.content,'html.parser')
week = soup.find(id='clickSunrise')

print(week)

Result:

<span class="sunriseX Bold sunrise-time" id="clickSunrise" style="white-space:nowrap;">...</span>

Those three dots were actually numbers, i need those numbers.

accdias
  • 5,160
  • 3
  • 19
  • 31
vinodh
  • 1
  • 3
  • _Those three dots were actually numbers, I need those numbers_ Can you explain what you mean? – AMC Feb 29 '20 at 01:01
  • @AMC I guess that on the webpage he's trying to scrape, the span with id clickSunrise has a specific number. He wants to scrape that number. – O'Niel Feb 29 '20 at 01:06
  • 1
    Does this answer your question? [Get value of span tag using BeautifulSoup](https://stackoverflow.com/questions/42175190/get-value-of-span-tag-using-beautifulsoup) – O'Niel Feb 29 '20 at 01:07
  • So you need `print(week.text)` instead. – accdias Feb 29 '20 at 01:14
  • It still isn’t clear to me what the whole three dots thing means. Have you tried anything, done any research? – AMC Feb 29 '20 at 01:20
  • those three dots are sun rise time – vinodh Feb 29 '20 at 04:48
  • @vinodh Can you elaborate? It’s unclear which part you’re struggling with. – AMC Feb 29 '20 at 12:37

2 Answers2

1

Hello I tested your code and seems like the website doesnt load the data until a browser requests the information. Since you are using the requests modules there is no browser.

You need to use a browser emulator like the selenium module to get that data. This module will open a browser for you and you can program it to navigate to that website wait until everything gets loaded and get the information for you.

Steps:

1-Install selenium

2-Download the chromedriver and put it somewhere (maybe in your project)

https://chromedriver.chromium.org/downloads

3-Learn selenium (this is an amazing tool to automate navigation of the web). This is an untested example just so you can get an idea (might work for you right away but might not)

import time
from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')  # Change this to your chromedriver path.

driver.get('https://www.suncalc.org/#/12.98,80.188,10/2020.02.21/15:51/1/3');
time.sleep(5) # Let the user actually see something!
clickSunrise = driver.find_element_by_id('clickSunrise')
print(clickSunrise.text)

I hope this helps!

Alvaro Bataller
  • 487
  • 8
  • 29
0

from selenium import webdriver

from selenium.webdriver.chrome.webdriver import WebDriver

from selenium.webdriver.common.keys import Keys

import time

driver:WebDriver=webdriver.Chrome(executable_path="D:\download\chromedriver_win32\chromedriver.exe")

driver.get("https://suncalc.org/#/12.05,80.04,17/null/null/324.0/2")

time.sleep(5)

altitude = driver.find_element_by_id("sunhoehe")

time.sleep(5)

print(altitude.text)

vinodh
  • 1
  • 3