Created
June 30, 2014 18:19
-
-
Save quasiben/8f42cc3152c9c0394866 to your computer and use it in GitHub Desktop.
python_postgres_frankenlanguage
This file contains 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
CREATE OR REPLACE FUNCTION bz_select_html(param_search text) | |
RETURNS SETOF text AS | |
$$ | |
from lxml import html | |
import requests | |
page = requests.get('http://econpy.pythonanywhere.com/ex/001.html') | |
param = param_search.lower() | |
tree = html.fromstring(page.text) | |
if param == 'buyers': | |
results = tree.xpath('//div[@title="buyer-name"]/text()') | |
elif param == 'prices': | |
results = tree.xpath('//span[@class="item-price"]/text()') | |
else: | |
results = [] | |
return results | |
$$ | |
LANGUAGE 'plpython2u' VOLATILE SECURITY DEFINER; | |
SELECT search_term, bz_select_html(search_term) As | |
result FROM (VALUES ('buyers')) As X(search_term); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results