+ 5

Sololearn Image and Username Url

How do I make the paragraph say my username, so if I change my username, it changes here too without me having to change it here as well? I already have the image data. But how do I get the profile username too? See code and please correct me where I'm wrong. https://code.sololearn.com/W91BG3ea7HKH/?ref=app

23rd Jun 2018, 10:45 PM
Andre Daniel
Andre Daniel - avatar
7 Respostas
+ 3
Sorry but SL dont has public API for their system. The only way to get it its scrape an SL page (at example your code page)
23rd Jun 2018, 11:26 PM
KrOW
KrOW - avatar
+ 4
I wamt to get the my username based off my sololearn ID (9594558) KrOW
23rd Jun 2018, 10:53 PM
Andre Daniel
Andre Daniel - avatar
+ 3
You can obtain the data through: https://cors-anywhere.herokuapp.com/https://www.sololearn.com/Profile/ <ID> That will return the code of the page, so by reviewing it you can obtain some information: let profileInfo = html.querySelector ('. user'); let name = profileInfo.querySelector ('. name'). innerText.trim (); let level = detailNodes.querySelectorAll ('div') [0] .innerText.trim (); let xp = detailNodes.querySelectorAll ('div') [1] .innerText.trim ();
23rd Jun 2018, 11:39 PM
Mickel
Mickel - avatar
+ 2
No, similarly to how you can get the profile picture with the ID (as shown in the code) I just want it to display "Andre Daniel" (or whatever I change my sololearn username to) from just the ID.
23rd Jun 2018, 10:57 PM
Andre Daniel
Andre Daniel - avatar
+ 1
You want get username to who run it or who save this code (you)?
23rd Jun 2018, 10:52 PM
KrOW
KrOW - avatar
+ 1
But if you want get your username in automatic way this mean that your code must handle multiple username (else you can put simply your username), right?
23rd Jun 2018, 10:55 PM
KrOW
KrOW - avatar
+ 1
Try to call this function on your code for get your username: function scrapeOwnUsername(){ var img= window.top.document.querySelector('.avatar > img') if(!img) return null else{ return img.title } } It work ONLY on SL Web version
23rd Jun 2018, 11:39 PM
KrOW
KrOW - avatar