Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

python - Read download a file using a link from an external csv file

I am trying to take a link from a csv file, download it, and change the filename, again using data from the csv file. Running the code below results in this error:

~AppDataLocalProgramsPythonPython39libsite-packages
equestssessions.py in get_adapter(self, url)
    740 
    741         # Nothing matches :-/
--> 742         raise InvalidSchema("No connection adapters were found for {!r}".format(url))
    743 
    744     def close(self):

InvalidSchema: No connection adapters were found for "('Links', 0       https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
1       https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
2       https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
3       https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
4       https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
                              ...                        
2790    https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
2791    https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
2792    https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
2793    https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
2794    https://eccdcf94738f34d487f9-0cee2c305dfdc401c...
Name: Links, Length: 2795, dtype: object)"

I have tried removing the header, and passing header = None through read_csv, but I then can't specify the column to read from. Anyone have any ideas on how to remedy this?

from urllib.parse import urlparse




firstNames = pandas.read_csv('e://DELETEAFTERUSE/PwC_links.csv', usecols=['FirstName'])
lastNames = pandas.read_csv('e://DELETEAFTERUSE/PwC_links.csv', usecols=['LastName'])
links = lastNames = pandas.read_csv('e://DELETEAFTERUSE/PwC_links.csv', usecols=['Links'])


def run():
    for item in firstNames.iteritems():
        firstname = item
        for item in lastNames.iteritems():
            lastname = item
            for item in links.iteritems():
                ftd = requests.get(item)
                split = urlparse.urlsplit(item)
                filename = "e:/DELETEAFTERUSE/" + firstname + lastname + split.path.split("/")[-1]
                open(filename, 'wb').write(ftd.content)

        
run()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...