Created
September 16, 2024 16:34
-
-
Save enpitsuLin/db278ebcdd132fd444be2f59ea6747ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cookies = [ | |
| 'sessionid=sessionid', | |
| 'sessionid_sign=sessionid_sign' | |
| ]; | |
| try { | |
| const response = await fetch('https://cn.tradingview.com/', { | |
| headers: { | |
| 'Cookie': cookies.join('; ') | |
| } | |
| }); | |
| const data = await response.text(); | |
| const parser = new DOMParser(); | |
| const doc = parser.parseFromString(data, 'text/html'); | |
| const scripts = doc.querySelectorAll('script'); | |
| const userInfoScript = Array.from(scripts).find(script => script.textContent.includes('var user = '))?.textContent; | |
| const userInfo = JSON.parse(userInfoScript.split('\n').find(i => i.includes('var user =')).replace(/^\t\tvar user = (.+);$/, '$1')) | |
| console.log(userInfo); | |
| } catch (error) { | |
| console.error('Error:', error); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment