upload a photo and copy link

51 views
Skip to first unread message

محمدمهدی خدادوست

unread,
Sep 5, 2023, 2:38:34 PM9/5/23
to beautifulsoup
<textarea class="form-control bg-light border-0" id="file-qr-result" style="margin-bottom: 10px;" rows="7">Scan a QR code to view the results here. </textarea>
This HTML is related to QR code scanning website
When we upload a file, the QR code link is replaced by this default text(Scan a QR code to view the results here.)
I upload a file to the website using the request library and extract the link using the beautiful soup library
But it still shows me the default text
Where did I go wrong?

like this👇

import requests
from bs4 import BeautifulSoup
upload_url = 'https://scanqr.org/'
files = {'file': open('ph.jpg', 'rb')}
response = requests.post(upload_url, files=files)
bs = BeautifulSoup(response.content, 'html.parser')
jj = bs.find('textarea', attrs={'class':'form-control bg-light border-0'}).text
print(jj)

Carlos

unread,
Jan 15, 2024, 5:05:50 PMJan 15
to beautifulsoup
Hello, Marco. That page uses a JavaScript function to read the content of the selected QR images. That is, the server response to your POST request is returning the same page as in a GET request: the page with the default "Scan a QR code to view the results here." message; and the QR code processing is done in your browser dynamically right when you selected it. In short, actually you are not uploading anything.

In order to extract the link from the QR, you need to extract the page (the requests module also extract the JavaScript code), manipulate the QR processing JavaScript function to pass the image you want to  it and then extract the link from the dynamically-generated HTML. I'm not really an expert on the package, but I'm sure Beautiful Soup cannot do that whole process by its own.

Hope this help you or others with similar problems.
Reply all
Reply to author
Forward
0 new messages