Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Real time data from web page with python

I am trying to create a real time report from the following website. 

The website updates data every hour by generating a new .zip file at the bottom of the list.

The difficulty is twofold:

  1. the .csv data is zipped;
  2. the name of the desired file changes every hour. Therefore, the url changes as well;

 

Thad_0-1653356874875.gif

 

I have written the following python script to download the latest report which works when I run it in the Command Prompt:

 

import requests
import os
import pandas as pd
from bs4 import BeautifulSoup
from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile

# important addresses
parent_dir = "http://www.nemweb.com.au"
URL = "http://www.nemweb.com.au/REPORTS/CURRENT/Short_Term_PASA_Reports/"
dest_dir = "D:\Python\DELWP"

# web scraping
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
zip_reports = soup.find_all("a")

report_link = parent_dir + zip_reports[-1].get("href")
resp = urlopen(report_link)

# extracting zip file and converting it to dataframe
zip_file = ZipFile(BytesIO(resp.read()))
fname = zip_file.namelist()[0]
df = pd.read_csv(zip_file.open(fname), skiprows=3, dtype=object)
zip_file.close()

print(df)

 

However, it doesn't work when I execute it from Python Script in PowerBI.

I get the following error:

 

python errorpython error

 

I have set the Python Home directory to the same address that I get when I type where python in the command prompt.

 

home directoryhome directory

execution and locationexecution and location

 

 

 

 

 

 

Can someone help, please?

 

PS: The solutions proposed by the responses in this community message don't work because they treat the url address as permanent.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

OK. I solved the problem. It was a matter of reinstalling a few packages.

I did the following:

  1. pip uninstall numpy; then pip install numpy;
  2. pip uninstall matplotlib; pip install matplotlib;
  3. pip install --upgrade Pillow

Cheers

View solution in original post

1 REPLY 1
Anonymous
Not applicable

OK. I solved the problem. It was a matter of reinstalling a few packages.

I did the following:

  1. pip uninstall numpy; then pip install numpy;
  2. pip uninstall matplotlib; pip install matplotlib;
  3. pip install --upgrade Pillow

Cheers

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.