Reputation: 27
There is the page where a random word generated. That word is in span
element which seems to be inserted by JavaScript. I wasn't able to find a link that provides the word from the server.
So I'm questioning what algorithm should I follow (how a front-end professional would do it) to find the link.
I tried to look at the button, the text, to observe click methods etc, but wasn't able to find it.
Upvotes: 0
Views: 77
Reputation: 653
If you mean a manual way. It really depends on the backend architecture
Upvotes: 0
Reputation: 143
Lets analyze this together. Before that we need to understand two things about how we see data from the server
With this in mind, I inspect the page and
step1: Check if this is dynamically loaded data: Go to Network tab. Here I clear all the network logs and try clicking the generate button. No APIs called
This clearly says the generated word is not dynamically loaded. The word is downloaded somewhere (hopefully not encrypted) on page load.
step2: Find the data by searching: Lets reload the page, and watch all the APIs that gets loaded on first time. And click on the left panel of network tab and press "ctrl+F" to search through all APIS
step3: Lets take the generated word, in this case "Hypnotisch", and search it
Conclusion: I was able to find a words.txt with all the list of words, that also containes "Hypnotisch"
The specific API that is called to get the txt file is : https://capitalizemytitle.com/wp-content/tools/random-word/de/words.txt
Open this link in new tab to get the list of words,
This is how I believe a professional front-end will find the data. Cheers!
Upvotes: 0
Reputation: 404
the are actually a few ways to create this generator. One of them is to manually create an array of words than using Math.random() to generate an index number to iterate over the array and show the word on button click. The array can also be stored on the server. The words can also be from an API random word generator. search on google you will find bunch of sites that provide random word generator APIs.
Hope I answered your question.
Upvotes: 0
Reputation: 76
As a FE developer, we follow below step to check for the service which is responsible for the changes on page.
for example, this service is getting called for your mentioned website. https://translate.googleapis.com/translate_a/t?anno=3&client=te_lib&format=html&v=1.0&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw&logld=vTE_20221115&sl=de&tl=en&tc=1&dom=1&sr=1&tk=352290.160565&mode=1
Upvotes: 0