This commit is contained in:
toom1996
2025-07-31 11:43:28 +08:00
parent 1768c86693
commit cc15942e79
5 changed files with 33 additions and 22 deletions

View File

@ -38,7 +38,7 @@ class BaiduRecordCommand extends BaseSpider
public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory)
{
parent::__construct('spider:baidu-record');
$this->log = $loggerFactory->get('log', 'command-baidu-record');
$this->log = $loggerFactory->get('log', 'command-spider-baidu-record');
}
public function configure()

View File

@ -8,7 +8,9 @@ use Hyperf\Command\Command;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Coroutine\Coroutine;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Laminas\Stdlib\ArrayUtils;
use Psr\Log\LoggerInterface;
use Swoole\Coroutine\Channel;
use Swoole\Timer;
use Symfony\Component\Console\Input\InputInterface;
@ -44,6 +46,8 @@ class BaseSpider extends Command
protected array $commandConfigure = [];
protected ?LoggerInterface $commandLogger = null;
private function init()
{
// 因为最外层还有个父协程, 所以加一
@ -79,7 +83,7 @@ class BaseSpider extends Command
return AppSpiderArticle::query()->where($condition)->first() ?: new AppSpiderArticle();
}
protected function request(string $url): array
protected function request(string $url, array $headers = []): array
{
$ch = curl_init();
curl_setopt_array($ch, array(
@ -88,10 +92,13 @@ class BaseSpider extends Command
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 15,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
));
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HEADER, false);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@ -130,7 +137,7 @@ class BaseSpider extends Command
$this->coroutineList[$cid] = 1;
}
protected function debugPrint(array|string $message = '', $level = 0)
protected function debugPrint(array|string $message = '', $level = 0):void
{
if ($this->getCommandConfigure('prod') === false) {
$printTime = date('H:i:s');