/ Published in: Python
This requires: * BeautifulSoup - http://www.crummy.com/software/BeautifulSoup/ * SoupSelect - http://code.google.com/p/soupselect/
Expand |
Embed | Plain Text
def pin_categories(): soup = BeautifulSoup.BeautifulSoup(URL("https://pinterest.com/").download()) cat_list = [] for c in select(soup, ".submenu a"): cat_list.append(c['href']) return cat_list def crawl_pin_category(category): #TODO: find next pages soup = BeautifulSoup.BeautifulSoup(URL("https://pinterest.com/" + category).download()) return harvest_pins(soup) def harvest_pins(soup): return [p.find("a",{"class":"PinImage ImgLink"})['href'] for p in select(soup, ".pin")] def grab_pin(pin_id): soup = BeautifulSoup.BeautifulSoup(URL("https://pinterest.com" + pin_id).download()) return { "url": select(soup, 'meta[property="og:url"]')[0]['content'], "title": select(soup, 'meta[property="og:title"]')[0]['content'], "description": select(soup, 'meta[property="og:description"]')[0]['content'], "image": select(soup, 'meta[property="og:image"]')[0]['content'], "pinboard": select(soup, 'meta[property="pinterestapp:pinboard"]')[0]['content'], "pinner": select(soup, 'meta[property="pinterestapp:pinner"]')[0]['content'], "source": select(soup, 'meta[property="pinterestapp:source"]')[0]['content'], "likes": select(soup, 'meta[property="pinterestapp:likes"]')[0]['content'], "repins": select(soup, 'meta[property="pinterestapp:repins"]')[0]['content'], "comments": select(soup, 'meta[property="pinterestapp:comments"]')[0]['content'], "actions": select(soup, 'meta[property="pinterestapp:actions"]')[0]['content'], }
Comments
Subscribe to comments
You need to login to post a comment.

Great post - this could potentially provide a really valuable functionality for SEO & Content Marketing. However, the 'Import BeautifulSoup' stuff seems missing from this script, and I can't seem to get the script to output anything.
I know it's been over a year since you posted this, but do you have any documentation or full .py script for this? I'd really love to get this working and start tweaking it. It provides a great example of the functionality of BeautifulSoup. Thanks!