Forums

Requesting a URL from a local File

I have uploaded and html file to a local directory on pythonanywhere which I can see via the browser .. but I want to access it via the console... when I do this I get a pythonanwhere web page back saying" Sorry, there was an error connecting to the server. <br/>Please try again in a few moments.."

import requests  
url ="https://www.pythonanywhere.com/user/thiw/files/home/thiw/RA2016/artworks2016.html"
r = requests.get(url)

Is there anyway that I can access this? (e.g include my username / password in URL). Thanks

set up a web site with static files mapping

The URL you give is the one for viewing a file from a browser session that is logged in to your account -- so a request made by code (which isn't running in such a session) doesn't have access to it.

@rcs1000's suggestion may be the right way to do what you want, but just in case your use case is not what we think it is, could you explain in a bit more detail what you're trying to do?

Hi... thanks for the answers.

I'm quite new to data scraping with Python. Basically I'm trying to scrape a webpage that only shows all the data when you scroll down. So I just manually scrolled down the whole page and then saved it to my local drive, then uploaded it to Python anywhere thinking it would be easier to read ! Seems and odd way round but then thought it would work !

After you have uploaded that html page, is the goal to run a python script that takes the page, parses/processes it, and then gives you back useful information?

In that case, you should be accessing your file like it is a file on disk, by

with open('/home/thiw/RA2016/artworks2016.html', 'r') as f:
    f.read()

Absolutely spot on .... that's so much that worked a treat. Here is the code that worked so I can now process it in BS. Thanks!

from bs4 import BeautifulSoup                       # Beautiful Soup Version 4
RA_Works = 0                                        # Initiate the Count

f = open('/home/thiw/RA2016/artworks2016.html', 'r')
s = f.read()
soup = BeautifulSoup(s,"lxml")

I need to use URL somewhere, so that file can be accessible by anyone without login, in short it should available on internet online. Please help me , How can we do it on pythonanywhere, I uploaded file in my home , how to get its proper URL

Check out our help pages on this topic.

how to link a url to html's template directory?????/

Did you read our help pages on this topic?