Answer the question
In order to leave comments, you need to log in
How to send a photo to the site through a form and return a link?
The site has an image upload form, after uploading the image, a download link is displayed (namely, an attribute appears in the form tag):
<form method="GET" id="file_link" action="/output/20200702125307337580.jpg">
url = 'http://color.photofuneditor.com/ceremony'
link_img[user_id] = src
data = {'name': 'file', 'type': 'submit'}
files = {'file': (link_img[user_id], open(link_img[user_id], 'rb'))}
req = requests.get(url, data=data, files=files)
if req.ok:
bot.send_message(message.chat.id, "Ждем 15с")
time.sleep(15)
img = requests.get('http://color.photofuneditor.com/ceremony')
soup = BeautifulSoup(img.text, "lxml")
img_p = soup.find('form', {'id': 'file_link'})
print(img_p.get('action')) #выводит None
Answer the question
In order to leave comments, you need to log in
It shouldn't show up there.
POST to color.photofuneditor.com/ceremony-vegas
Parameter fileToUpload Parameter
content - base64 images
Response - new file name
import requests
import base64
with open("nums.jpeg", "rb") as image_file:
image_hash = base64.b64encode(image_file.read()).decode("utf-8")
encoded_image = 'data:image/jpeg;base64,{}'.format(image_hash)
payload = {'fileToUpload': encoded_image}
r = requests.post('http://color.photofuneditor.com/ceremony-vegas', data=payload)
if r.status_code == 200:
image_url = 'http://color.photofuneditor.com/output/{}'.format(r.json()['file_link'])
r = requests.get(image_url)
with open('new_image.jpg', 'wb') as f:
f.write(r.content)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question