-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathScraper.php
24 lines (20 loc) · 923 Bytes
/
Scraper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
/**
* A simple scraper which just send an X-SQL request to the pulsar server and get the scrape result
* */
$url = "http://localhost:8182/api/x/e";
$sql = "select
dom_first_text(dom, '#productTitle') as title,
dom_first_text(dom, '#price tr td:contains(List Price) ~ td') as listprice,
dom_first_text(dom, '#price tr td:matches(^Price) ~ td, #price_inside_buybox') as price,
array_join_to_string(dom_all_texts(dom, '#wayfinding-breadcrumbs_container ul li a'), '|') as categories,
dom_base_uri(dom) as baseUri
from
load_and_select('https://www.amazon.com/dp/B0C1H26C46', ':root')";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
# curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sql);
$output = curl_exec($ch);
curl_close($ch);
# echo $output;