0

I want to extract data from multiple URLs, but the URLs are in a column of a data frame.

I tried data extraction with the code below but no luck.

from urllib.request import urlopen,Request
link = data.column1
f = urlopen(link)
myfile = f.read()
print(myfile)

It shows:

AttributeError: 'Series' object has no attribute 'type'.

Please help with the code. Thank you

MLavoie
  • 9,671
  • 41
  • 36
  • 56

1 Answers1

1

The problem is you're trying to perform the action on the entire series of URLs at once.

Try iterating over the items of data.column1 and don't forget to dispose resourses using with in order to prevent potential memory leaks:

from urllib.request import urlopen

for link in data['column1']:
    with urlopen(link) as response:
        myfile = response.read()
        print(myfile)
ayorgo
  • 2,803
  • 2
  • 25
  • 35