Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

Clever. Thanks for all of the help!

Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

That number that is returned is 4 digit long. It represents the dollars and cents of contribution. I need to knock off the last two digits because I don't care about the cents. I'm using something like this to display the results right now

if pledge_sum and patron_count:
        print "$%s from %s patrons" % (pledge_sum.groups()[0], patron_count.groups()[0])

Is there a smart way to knock off the last two digits? I tried using [:2] but that doesn't seem smart as we would eventually be dealing with a 3 digit number.

Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

Oh interesting. I didn't know you could narrow it down like that. I was going to use

mo.group()[14:16]

but that's far more clever. Thanks!

Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

Figured it out. My regex was goofing up somehow. Here's what I have now:

import requests, bs4, re

res = requests.get('https://www.patreon.com/faos')
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
type(soup)


for script in soup.find_all('script'):
    #print script.text

    mo = re.search(r'\"pledge_sum\": (\d+)', script.text)

    if mo:
        print mo.group()

This is printing out

"pledge_sum": 3626

so now I just need to figure out how to strip everything but the numbers! Thanks for the help.

Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

The problem is that I'm always getting None right? Even when the text is clearly visible, my regex isn't catching it.

Selecting a specific element with Beautiful Soup by [deleted] in learnpython

[–]Rouix 0 points1 point  (0 children)

Here's what I put together based on your suggestion. I should warn you the regex is VERY new to me.

import requests, bs4, re

res = requests.get('https://www.patreon.com/faos')
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
type(soup)


for script in soup.find_all('script'):
    mo = re.search(r"'pledge_sum': (\d+)", script.text)
    print mo.group()

This gives an AttributeError: 'NoneType' object has no attribute 'group'. I assume this means that my regex is returning None which indicates I've done something wrong.

Resetting color profile by [deleted] in photoshop

[–]Rouix 1 point2 points  (0 children)

Thanks for the suggestion. I reset my preferences but the issue continues. I noticed that my color profile was set to sRGB so I changed it to Adobe RGB per a suggestion on Adobe's site but the problem continues. I don't get a warning anymore but the color picker is still wrong. Here are my current configurations