Eager to get started? Start by authenticating. Once authenticated, LSD lang can be run in the workbench or python.
If you’re non technical, explore public queries on the nexus or make them using our browser (download) (docs).
Let’s take a look at a simple example to extract data from a web page:
FROM https://news.ycombinator.com
|> SELECT a AS post
|> GROUP BY span.titleline
So what did that code do?
a
tag (post title) to be extracted.span.titleline
class.post
.FROM, SELECT, and GROUP BY are all keywords with unique functionality to control the browser to wrangle data on the web.
To run this code from python, you can use the following script:
# The postgres adapter used to connect to LSD with
import psycopg2
# Setting up a connection to LSD via postgres
conn = psycopg2.connect("host='lsd.so' dbname='andrea@lsd.so' password='<api key>'")
with conn.cursor() as curs:
curs.execute("""
PORTAL <| OPEN |
FROM https://news.ycombinator.com
|> SELECT a AS post
|> GROUP BY span.titleline
""")
rows = curs.fetchall()
for row in rows:
print(row)
Remember to install psycopg2 and fill in your api key (available from your profile). What you’ll notice is the syntax is the same in python as the code we ran in the workbench.
PORTAL <| OPEN |
post_container <| div.details |
post <| a |
domain <| a.domain |
author <| a.u-author.h-card |
FROM https://lobste.rs/
|> GROUP BY post_container
|> SELECT post, domain, author
So what did that code do?
span.titleline
tag as we did in the first example.This example is similar to the first, but it shows how to activate the portal, assign variables to tags, and pull multiple columns from the page (in a repeating structure). The next example will dig deeper showing you how to programatically control a browser.
PORTAL <| OPEN |
calculators <| https://www.smooth-on.com/support/calculators/ |
pour_on_mold <| div[data-calcid="pour-mold"] |
product_dropdown <| #pour-prod |
dropdown_value <| "24.7" |
model_volume_input <| #pour-model-volume |
model_volume <| "12" |
box_volume_input <| #pour-box-volume |
box_volume <| "20" |
calculate_button <| #pour-calculate |
estimate <| #pour-results |
FROM calculators
|> CLICK ON pour_on_mold
|> CHOOSE IN product_dropdown dropdown_value
|> ENTER INTO model_volume_input model_volume
|> ENTER INTO box_volume_input box_volume
|> CLICK ON calculate_button
|> SELECT estimate
So what did that code do?
(ignoring portal opening and variable assignment, though you’ll notice the portal is a video this time.)