AnthonyZJiang / Microsoft-Rewards-Bot

Microsoft Rewards (Bing Rewards) Bot - automated selenium python bot
27 stars 4 forks source link

ERROR :: root :: Cannot find key "userStatus" #29

Open Chris9a opened 1 year ago

Chris9a commented 1 year ago

I have had a userStatus error for a week now. Any way to fix it?

ashanrath commented 1 year ago

I have had a userStatus error for a week now. Any way to fix it?

Yep I've been testing a change to the xpath for it. It's in the stats.py file, function _get_user_status_json.

I'll post it when I'm at my PC later today.

Update - try this tweak, I've commented out the old version of the line.

    def _get_user_status_json(self):
        js = self._browser.find_elements(By.XPATH, 
            '//script[text()[contains(., "userStatus")]]')
        if not js:
            return {}

        matches = re.search(
            #r'(?=\{"userStatus":).*(=?\}\};)', js[0].get_attribute('text'))
            r'(?=\{"userStatus":).*(=?\};)', js[0].get_attribute('text'))
        if not matches:
            return {}
        return json.loads(matches[0][:-1])
Chris9a commented 1 year ago

Awesome. Your fix worked, thank you.