You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-26Lines changed: 42 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,33 @@ Most of the PHP parsers I encountered in the past were either too complicated, *
4
4
5
5
# pQuery Web Scraper tutorial
6
6
## Getting started
7
-
To start coding with pQuery, just include the main php file and create a Web Scraper class object and send the parameters through the constructor, it will know if you sent a URL or an HTML string:
8
-
7
+
To start coding with pQuery simply include the main PHP file in this repository and initilize an object class like this:
9
8
```php
9
+
// include webscraper.php file
10
10
include "path/webscraper.php";
11
-
12
-
$doc = new WebScraper("https://www.examplelink.com");
13
-
11
+
// create a new object
12
+
$doc = new WebScraper();
13
+
```
14
+
In case you want to load a string containing your HTML or XML:
15
+
```php
16
+
$doc->loadHTML($html);
14
17
// or
15
-
16
-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$yourhtml."</body></html>");
17
-
18
-
// both work
18
+
$doc->loadXML($xml);
19
19
```
20
-
And then, you can "echo" your parsed web page by using the `echo` function:
21
-
20
+
And when you finish parsing your doc you can "echo" your parsed web page by using the `echo` function:
22
21
```php
23
-
24
22
$doc->echo();
25
-
26
23
```
24
+
But, for now, we will be using this initialization:
25
+
```php
26
+
include "path/webscraper.php";
27
+
$doc = new WebScraper();
28
+
$doc->loadHTML($html);
27
29
28
-
Simple as that!
30
+
// code
29
31
32
+
$doc->echo();
33
+
```
30
34
## How do I select nodes within my HTML document?
31
35
For this, we use `query`, or its simplified version: `Q`, as its parameter we can pass in a string with the CSS query we want, for example: `$doc->Q("div.box > span#tooltip")`.
32
36
@@ -131,7 +135,8 @@ Wrap or unwrap node elements with other node elements.
131
135
132
136
```php
133
137
include "path/webscraper.php";
134
-
$doc = new WebScraper("<!DOCTYPE html><html><body>".$html."</body></html>");
0 commit comments