-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* + blogspot (RSS feed) scrapers, - deprecated scrapers * + intgration & unit tests, + fix HideMyIpScraper tests * + Fix bug and add test for BlogSpotProxyScraper & ProxyServerListScraper * ~ re-arrange code & add try catch stmt * ~ update try-catch exception type
- Loading branch information
Showing
32 changed files
with
972 additions
and
718 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Vantoozz\ProxyScraper\Scrapers; | ||
|
||
use Vantoozz\ProxyScraper\Enums\Metrics; | ||
use Vantoozz\ProxyScraper\Exceptions\HttpClientException; | ||
use Vantoozz\ProxyScraper\Exceptions\InvalidArgumentException; | ||
use Vantoozz\ProxyScraper\Exceptions\ScraperException; | ||
use Vantoozz\ProxyScraper\HttpClient\HttpClientInterface; | ||
use Vantoozz\ProxyScraper\Metric; | ||
use Vantoozz\ProxyScraper\Proxy; | ||
use Vantoozz\ProxyScraper\ProxyString; | ||
use Vantoozz\ProxyScraper\Text; | ||
|
||
/** | ||
* Class AbstractRssBloggerScraper | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
abstract class AbstractRssBloggerScraper implements ScraperInterface | ||
{ | ||
/** | ||
* @var HttpClientInterface | ||
*/ | ||
private $httpClient; | ||
|
||
/** | ||
* FreeProxyListScraper constructor. | ||
* @param HttpClientInterface $httpClient | ||
*/ | ||
public function __construct(HttpClientInterface $httpClient) | ||
{ | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
/** | ||
* @return \Generator|Proxy[] | ||
* @throws ScraperException | ||
*/ | ||
public function get(): \Generator | ||
{ | ||
try { | ||
$html = $this->httpClient->get($this->rssBloggerUrl()); | ||
} catch (HttpClientException $e) { | ||
throw new ScraperException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
|
||
if (!(new Text($html))->isXml()) { | ||
throw new ScraperException('Invalid XML'); | ||
} | ||
|
||
$feed = simplexml_load_string($html); | ||
yield from $this->fetchFeed($feed); | ||
} | ||
|
||
/** | ||
* @param \SimpleXMLElement $feed | ||
* @return \Generator | ||
*/ | ||
private function fetchFeed(\SimpleXMLElement $feed) | ||
{ | ||
foreach ($feed->entry as $entry) { | ||
preg_match_all('/\d+\.\d+\.\d+\.\d+:\d{1,5}/m', (string)$entry->content, $matches); | ||
foreach ($matches[0] as $proxyString) { | ||
try { | ||
$proxy = (new ProxyString($proxyString))->asProxy(); | ||
$proxy->addMetric(new Metric(Metrics::SOURCE, static::class)); | ||
yield $proxy; | ||
} catch (InvalidArgumentException $e) { | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract protected function rssBloggerUrl(): string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types = 1); | ||
namespace Vantoozz\ProxyScraper\Scrapers; | ||
|
||
/** | ||
* Class BlogspotProxyScraper | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class BlogspotProxyScraper extends AbstractRssBloggerScraper | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function rssBloggerUrl(): string | ||
{ | ||
return 'https://blogspotproxy.blogspot.com/feeds/posts/default'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.