Dance Party2
Dance Party2

Reputation: 7536

Python Requests: Use * as wildcard part of URL

Let's say I want to get a zip file (and then extract it) from a specific URL. I want to be able to use a wildcard character in the URL like this:

https://www.urlgoeshere.domain/+*+-one.zip

instead of this:

https://www.urlgoeshere.domain/two-one.zip

Here's an example of the code I'm using (URL is contrived):

import requests, zipfile, io
year='2016'
monthnum='01'
month='Jan'

zip_file_url='https://www.urlgoeshere.domain/two-one.zip'
r = requests.get(zip_file_url, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall()

Thanks in advance!

Upvotes: 0

Views: 4254

Answers (2)

Andrei-Marius Longhin
Andrei-Marius Longhin

Reputation: 563

I'm not sure if this helps you, but Flask has a feature that works similarly to what you require. Here's a working example:

@app.route('/categories/<int:category_id>')
def categoryDisplay(category_id):
''' Display a category's items
'''
   # Get category and it's items via queries on session
   category =session.query(Category).filter_by(id=category_id).one()
   items = session.query(Item).filter_by(category_id=category.id)

   # Display items using Flask HTML Templates
   return render_template('category.html', category=category, items=items,
          editItem=editItem, deleteItem=deleteItem, logged_in = check_logged_in())

the route decorator tells the web server to call that method when a url like */categories/(1/2/3/4/232...) is accessed. I'm not sure but I think you could do the same with the name of your zip as a String. See here (project.py) for more details.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799370

HTTP does not work that way. You must use the exact URL in order to request a page from the server.

Upvotes: 2

Related Questions