Forked from justinabrahms/gist:bdcbc7a2da010d7aff6e
Created
February 3, 2015 00:22
-
-
Save schmichael/4bffb928420e2639e83b 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
from pyquery import PyQuery | |
import requests | |
from random import choice | |
url = 'http://www.johnsmarketplace.com/Kegs/' | |
query = 'td table tr' | |
def main(): | |
possibilities = [] | |
resp = requests.get(url) | |
pq = PyQuery(resp.text) | |
for num, row in enumerate(pq.find(query)): | |
if num == 0: | |
continue # skip header | |
if len(row.getchildren()) < 5: | |
continue | |
name = row.getchildren()[0].text | |
kind = row.getchildren()[5].text | |
if not kind: | |
continue | |
if not name or 'bud' not in name.lower(): | |
continue | |
possibilities += [name] | |
print choice(possibilities) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment