很久没放干货了,找到一个几个月前写的实例现在放出。
爬的是一言的接口,自动保存为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&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();}
?>

Last modification:June 27, 2018
If you think my article is useful to you, please feel free to appreciate