File tree Expand file tree Collapse file tree 5 files changed +371
-112
lines changed Expand file tree Collapse file tree 5 files changed +371
-112
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Http \Controllers ;
4
+
5
+ use Illuminate \Http \Request ;
6
+
7
+ use App \Http \Requests ;
8
+ use Goutte \Client ;
9
+ use App \Http \Controllers \Controller ;
10
+
11
+ class WebScrapingController extends Controller
12
+ {
13
+ protected $ crawler ;
14
+
15
+ /**
16
+ * [__construct description]
17
+ */
18
+ public function __construct ()
19
+ {
20
+ $ this ->client = new Client ();
21
+ }
22
+
23
+ /**
24
+ * Return all data to the Stripe API dashboard
25
+ * @return mixed
26
+ */
27
+ public function getPage ()
28
+ {
29
+ $ links = $ this ->getData ('https://news.ycombinator.com/ ' );
30
+
31
+ return view ('api.scraping ' )->withLinks ($ links );
32
+ }
33
+
34
+ /**
35
+ * Scrape the Links
36
+ * @param $siteToCrawl
37
+ * @return array
38
+ */
39
+ public function getData ($ siteToCrawl )
40
+ {
41
+ $ crawler = $ this ->client ->request ('GET ' , $ siteToCrawl );
42
+
43
+ $ arr = $ crawler ->filter ('.title a[href^="http"], a[href^="https"] ' )->each (function ($ element ) {
44
+ $ links = [];
45
+
46
+ array_push ($ links , $ element ->text ());
47
+
48
+ return $ links ;
49
+ });
50
+
51
+ return $ arr ;
52
+ }
53
+ }
Original file line number Diff line number Diff line change 86
86
'middleware ' => ['auth ' ]
87
87
]);
88
88
89
+ Route::get ('/api/scraping ' , [
90
+ 'uses ' => 'WebScrapingController@getPage ' ,
91
+ 'as ' => 'api.scraping ' ,
92
+ 'middleware ' => ['auth ' ]
93
+ ]);
94
+
89
95
Route::post ('/tweet/new ' , [
90
96
'uses ' => 'TwitterController@sendTweet ' ,
91
97
'as ' => 'tweet.new ' ,
Original file line number Diff line number Diff line change 14
14
"graham-campbell/github" : " ^4.2" ,
15
15
"thujohn/twitter" : " ^2.1" ,
16
16
"metalmatze/lastfm-api-wrapper" : " dev-master" ,
17
- "aloha/twilio" : " ^2.0"
17
+ "aloha/twilio" : " ^2.0" ,
18
+ "fabpot/goutte" : " ^3.1" ,
19
+ "codeguy/arachnid" : " ^1.0"
18
20
},
19
21
"require-dev" : {
20
22
"fzaninotto/faker" : " ~1.4" ,
You can’t perform that action at this time.
0 commit comments