×

一言爬虫php实例

hqy hqy 发表于2025-01-09 15:54:07 浏览6 评论0

抢沙发发表评论

爬的是一言的接口,自动保存为text.txt使用|分割


<?php

function httpGet($url) {

    $curl = curl_init();

    $httpheader[] = "Accept:*/*";

    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";

    $httpheader[] = "Connection:close";

    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );

    curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($curl, CURLOPT_TIMEOUT, 3);

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

    curl_setopt($curl, CURLOPT_URL, $url);

    $res = curl_exec($curl);

    curl_close($curl);

    return $res;

}

if($_GET{'t'}==1){

while($t<=100){

    echo httpGet('http://api.hitokoto.cn/?c=f&amp;encode=text');

    echo '|';

    $t++ ;}

    exit();}else{

  while($t<=200){

    $textx=httpGet('https://api.lwl12.com/hitokoto/main/get');

    $text=$textx.'|';

$myfile = fopen("text.txt", "a+") or die("Unable to open file!");

fwrite($myfile, $text);

fclose($myfile);

    $t++ ;}exit();}

?>


打赏

本文链接:https://www.kinber.cn/post/4553.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客