예제 #1
0
파일: emails.php 프로젝트: widmogrod/sengin
 //$miasta = array_slice($miasta, 328*2);
 $miasta = array('Żywiec');
 $baseKeyword = 'pozycjonowanie ';
 $emailFileStorage = sprintf('%s/email-%s-%s.csv', __DIR__, date('Ymd-His'), $baseKeyword);
 $handle = fopen($emailFileStorage, 'a');
 fputcsv($handle, array('city', 'email', 'title', 'url', 'position', 'facebook'));
 $cacheOptions = new DataSource\Options\Cache();
 $cacheOptions->setCacheDir(__DIR__ . '/cache');
 //    register_shutdown_function(function() {
 //        global $handle;
 //        fclose($handle);
 //    });
 foreach ($miasta as $i => $miasto) {
     $query = $baseKeyword . ' ' . $miasto . ' +kontakt +email';
     echo "\ncity: {$miasto} ({$i} from " . count($miasta) . ") query: {$query} \n";
     $definition = new Definition\GoogleSearch();
     $definition->setQuery($query);
     $definition->setOnPage(100);
     $source = new DataSource\Url($definition);
     $source = new DataSource\Cache($source, $cacheOptions);
     $extractor = new Extractor\GoogleSearch($source);
     try {
         $extraction = $extractor->extract();
     } catch (\Exception $e) {
         echo $e->getMessage() . ' ' . $result->getUrl() . "\n";
         goto save;
     }
     $searchResults = $extraction->getSearchResults();
     $it = new \ArrayIterator($searchResults);
     $data = array();
     while ($it->valid()) {
예제 #2
0
파일: draft.php 프로젝트: widmogrod/sengin
//    {
//        /** @var $result \Sengin\Extraction\SearchResult */
//        $result = $it->current();
//
//        echo sprintf(
//            'pos:%s, url:%s, title: %s'."\n",
//            $result->getPosition(),
//            str_pad($result->getUrl(), 200),
//            $result->getTitle()
//        );
//
//        $it->next();
//    }
//}
namespace Sengin {
    $definition = new Definition\GoogleSearch();
    $definition->setQuery('tłumacz języka angielskiego darmowy');
    $definition->setOnPage(10);
    $source = new DataSource\Url($definition);
    //    echo $source->getCacheKey();
    $cacheOptions = new DataSource\Options\Cache();
    $cacheOptions->setCacheDir(__DIR__ . '/cache');
    $source = new DataSource\Cache($source, $cacheOptions);
    $extractor = new Extractor\GoogleSearch($source);
    $extraction = $extractor->extract();
    $searchResults = $extraction->getSuggestedKeywords();
    $it = new \ArrayIterator($searchResults);
    while ($it->valid()) {
        /** @var $result \Sengin\Extraction\SuggestedSearch */
        $result = $it->current();
        echo $result->getKeyword() . "\n";