提取 CSRF Token。
(self)
| 87 | self.csrf_token = None |
| 88 | |
| 89 | def fetch_csrf_token(self): |
| 90 | """ |
| 91 | 提取 CSRF Token。 |
| 92 | """ |
| 93 | url = 'https://greasyfork.org' |
| 94 | response = self.session.get(url) |
| 95 | if response.status_code == 200: |
| 96 | soup = BeautifulSoup(response.text, 'html.parser') |
| 97 | csrf_token_meta = soup.find('meta', {'name': 'csrf-token'}) |
| 98 | if csrf_token_meta: |
| 99 | self.csrf_token = csrf_token_meta.get('content') |
| 100 | return self.csrf_token |
| 101 | else: |
| 102 | raise ValueError("CSRF Token meta tag not found") |
| 103 | else: |
| 104 | raise Exception( |
| 105 | f"Failed to fetch the page. Status Code: {response.status_code}") |
| 106 | |
| 107 | def login(self, email, password, totp): |
| 108 | if self.csrf_token is None: |
no test coverage detected