Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does Python output an empty list when it should have output a list of URLs?

I ran the script below to grab text from a Pastebin text file and turn it into a list. Unfortunately, it’s printing an empty list. Can anyone help me diagnose why this is the case? Thank you!

Command typed:

script.py -id 049YJMdV

Script

import requests, re, argparse

parser = argparse.ArgumentParser()
parser.add_argument('-id','--id', required=False)
args = vars(parser.parse_args())
id = args['id']

link = "https://web.archive.org/web/20150611011149/http://pastebin.com/raw.php?i={}".format(id)
data = []

links = requests.get(link).text
urls = re.findall(r'https?://[^\s<>"]+[|www\.^\s<>"]+', links)


print(data)

Output

[]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The array is getting printed empty because you’re defining

data = []

without actually appending anything to it at all. Therefore, its behaving as expected because nothing has been added to it and prints an empty list.

Also, you have the id as not required. However, it will throw an exception since no id is provided in the url. Would double check that as well.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading