3
3
35000sobak2020-07-02 11:28:27
Python
35000sobak, 2020-07-02 11:28:27

How to download a file from a tag using requests?

There is a button to download photos. In addition, the site generates the tag in this way:

<form method="GET" id="file_link" action="/output/20200702101111557143.jpg">

You need to download the file from this tag, you can even programmatically click on the (download) button and get the file. I tried this way, but, most likely, I'm doing something wrong:

if req.ok:
   img = 'http://color.photofuneditor.com/ceremony'
   bot.send_message(message.chat.id, "Идет обработка...")
   time.sleep(10)
   r = requests.get(img, files={'image': ('my_img.jpg', img.content, 'image/jpg')})
   img_file = file('/home/dir/images/', 'wb')
   img_file.write(img.content)
   img_file.close()

Error: AttributeError: 'str' object has no attribute 'content'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-02
@bacon

Well, it's probably logical that the string 'http://color.photofuneditor.com/ceremony'doesn't have the content attribute, doesn't it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question