I have a problem with links on my website. Please forgive me if this is asked somewhere else, but I have no idea how to search for this.
A little background on the current situation:
I've created a python program that randomly generates planets for a sci-fi game. Each created planet is placed in a text file to be viewed at a later time. The program asks the user how many planets he/she wants to create and makes that many text files. Then, after all the planets are created, the program zips all the files into a file 'worlds.zip'. A link is then provided to the user to download the zip file.
The problem:
The first time I run this everything works perfectly fine. When run a second time, however, and I click the link to download the zip file it gives me the exact same zip file as I got the first time. When I ftp in and download the zip file directly I get the correct zip file, despite the link still being bad.
Things I've tried:
When I refresh the page the link is still bad. When I delete all my browser history the link is still bad. I've tried a different browser and that didn't work. I've attempted to delete the file from the web server and that didn't solve the problem. Changing the html file providing the link worked once, but didn't work a second time.
Simplified Question:
How can I get a link on my web page to update to the correct file?
I've spent all day trying to fix this. I don't mind looking up information or reading articles and links, but I don't know how to search for this, so even if you guys just give me links to other sites I'll be happy (although directly answering my question will always be appreciated :)).
I don't know anything about Python, but in PHP, in some fopen modes, if a file is trying to be made with the same name as an existing file, it will cancel the operation.
Related
I am using Robocorp, an RPA platform.
In my bot, I have to click a link that automatically downloads a file. (the file name is generated randomly by the site)
I then need to rename the file and move it to a specific directory.
I have two questions on the best way to do this:
Should I simply change the Chrome settings on the RPA.Browser.Selenium library to ask for the download location upon downloading. (Note that I have not been able to get this to work in Robocorp)
Or should I wait for a new file to appear in the bot's "Downloads" folder and then manage that file from there?
Above is an image of one of my many attempts of editing the 'options' argument of the Open Available Browser task to ask me where to save the file prior to downloading. I noticed there is also a 'download' argument but I do not believe it is the right one to edit based on some research.
https://robocorp.com/docs/libraries/rpa-framework/rpa-browser/keywords#open-available-browser
Here is the docs page for the "Open Available Browser' task in Selenium that shows all of its arguments.
Is there a more reliable way to do this?
This is a bit tricky scenario. First, I will start by stating I do not have any experience in Robocorp tool. But this is a generic problem in test automation and RPA.
There are few things to consider while waiting for a file to download including;
Is the file fully downloaded?
What is the max time I need to allow for download?
What if there are pervious files in the folder with similar name?
So to overcome this I would take the following approach. (tested and working for more than 4+ prod level automation frameworks with >20k scenarios)
Maintain a unique "Downloads" folder for each execution. Do this by creating a new folder with unique name and setting that as the downloads folder at the beginning of the run.
In a loop, check the download file size continuously and wait for the file size to NOT increase to check the file is fully downloaded.
??? profit ???
I have done a lot of research but I can find a way to get the url of a file already downloaded..
I want to get the urls to make a program to sort my files by them.
If anyone have an idea to get that or to make that in an other way im glade to hear it !
Sorry for my bad English !
I doubt that it is in general possible, because data like these is not stored in file's metadata. If your script makes the download, you can save the link in code and then use it to sort your files, but if files are downloaded by the user it is impossible.
https://gyazo.com/4472adaefcd169a548253d6101041af8
Was recently making a bot to automatically post an "ad" to a site when launched , however i do need pictures and i researched ways to upload pictures all i could find was :Imagepath=os.path.abspath('.\folder1\subfolder2\file1.jpg') driver.find_element_by_id("ImageUploadButton").clear() driver.find_element_by_id("ImageUploadButton").send_keys(Imagepath) and me being new to python or coding in general I have no idea what ".\folder1\subfolder2\file1.jpg" accesses
Make sure you have your actual pathname put in there instead of writing '\folder1\subfolder2\file1.jpg' - that looks like it's just placeholder stuff that the person who wrote the sample code you got put in there to stand in for your actual path.
So if the image you want to upload is in \Volumes\username\bob\Desktop\ and it's called cats.jpg, you need to put '.\Volumes\username\bob\Desktop\cats.jpg' in where '.\folder1\subfolder2\file.jpg' is right now.
I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py
I would like to use Qualtrics to get ratings for over 700 images (i.e., participants will have to indicate how negative or positive they find them). The question will be exactly the same for each image, yet there seems to be no straightforward way to just create the question once and then loop over all the images I want participants to rate. Obviously, I don't really want to write the same question 700 times.
I found a relevant answer here on Stack Overflow that seems to suggest a good solution - here it is: Randomization in Qualtrics using Photos or Graphics and Loop and Merge . My question, however, is not a mere duplicate of this, as I have troubles running the web scraping code at the bottom (I am a very inexperienced coder with limited Python knowledge), thus have some follow-up questions.
I tried running the above mentioned code a number of different ways (I have BeautifulSoup and Selenium):
1) create a .py file (e.g., getURL.py) with all the code suggested, and then just run it from the PowerShell (the only way I know how to run python code) with
python getURL.py
This opens up a Chrome browser (data:,), but the file it creates in the end is empty. I'm guessing by the time I navigate to the library the code has already run and reached the end of the for loop.
2) I tried running it line by line in the Python interpreter in the PowerShell, like this: I would go through the first block, that would bring up the Browser, then I'd navigate to the photo library within the browser (am I supposed to do anything other than just brining up the site in the browser?). Once that's done I'd move on to the next block of code with the for loop - I'd paste it into the interpreter, either as a block or line by line - but python just doesn't seem to execute that.
Could anyone tell me how to run that code?
ALTERNATIVELY: does anyone know an easier way a) to get Qualtrics to loop over images, or b) to get a list of 700 URLs quickly?
Thank you very much for the help.
You didn't say where the images are stored. If they are stored in Qualtrics this is fairly easy:
Get a list of photo urls or image ids (If photos are stored in your Qualtrics library, go Account Setting/Qualtrics IDs. Then click on the library where the photos are stored. Copy the image ids and paste them in a spreadsheet.)
Edit your spreadsheet as needed.
Copy and paste your urls or image ids from the spreadsheet into the loop & merge setup. This can be done all at one time.
Create your question in the loop & merge block. Include an html <img> tag in the appropriate place. You'll pipe your url or image id into the appropriate place in the src attribute. For example, if you are using image ids with a name in field 1 and the image id in field 2, the html might look like:
<img src="https://survey.qualtrics.com/ControlPanel/Graphic.php?IM=${lm://Field/2}" alt="${lm://Field/1}" border="0">