Doscripter - 简单,强大,实用!


Doscripter,是由魔爪团队历时5年开发出来的一套脚本引擎,他热衷于线程、爬虫、字符串、正则表达式、智能分析等等工作。不需要复杂的知识,您就可以写出许多实用的小工具。
特性一览:
1、Thread    - 多线程,脚本中您可以随时创建新的线程以及调度您的线程完成各种工作。
2、Language  - 多语法,您可以在pascal/js/c/basic四种语法中任选一种语法编写脚本,支持多种语言嵌套。
3、Simple    - 够简单,简单的几句代码就能实现各种操作:线程控制、字符串分析等等。
3、Power     - 够强大,强大字符串处理,支持MYSQL\SQLITE\SQLSERV\HTTP\FTP,还可以自己写扩展完善
4、Utility   - 够实用,支持ide模式和命令行模式运行,占用资源小,稳定
----------------------------
以下教程为每日一课,欢迎大家一起学习使用Doscripter。 
点击这里打包下载所有例子(Download All Example) 更新时间:[2013-12-01] 

学习使用Doscripter! - Hello World(Learn Hello World!)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin
  3.    echo('Hello World!');
  4. end.
  1. #language js
  2. echo("Hello World!");
  1. #language c
  2. {
  3.    echo("Hello World!");
  4. }
  1. #language basic
  2. echo("Hello World!")

第1课 - 常用语法(Statement)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin
  3.   i := 10;
  4.   if i = 1 then
  5.   begin
  6.     alert('i=1');
  7.   end
  8.   else begin
  9.     for i := 0 to 10 do
  10.     begin
  11.       case i of
  12.         1:
  13.           echo(i+1);
  14.         2..9:
  15.           echo(i);
  16.         else
  17.           echo(i+10);
  18.         end;
  19.     end;
  20.     while i<20 do
  21.     begin
  22.       echo(i);
  23.       inc(i);
  24.     end;
  25.   end;
  26. end.
  1. #language js
  2. var i = 10;
  3. if(i==1){
  4.   alert("i=1");
  5. }else{
  6.     for(i=0;i<=10;i++){
  7.       switch(i){
  8.         case 1:{
  9.           echo(i+1);break;
  10.         }
  11.         case 2:{
  12.           echo(i);break;
  13.         }
  14.         default:{
  15.           echo(i+10);break;
  16.         }
  17.       }
  18.     }
  19.     while(i<20){
  20.       echo(i);
  21.       i++;
  22.     }
  23. }
  1. #language c
  2. {
  3.   int i = 10;
  4.   if(i==1){
  5.     alert("i=1");
  6.   }else{
  7.     for(i=0;i<=10;i++){
  8.       switch(i){
  9.         case 1:{
  10.           echo(i+1);break;
  11.         }
  12.         case 2:{
  13.           echo(i);break;
  14.         }
  15.         default:{
  16.           echo(i+10);break;
  17.         }
  18.       }
  19.     }
  20.     while(i<20){
  21.       echo(i);
  22.       i++;
  23.     }
  24.   }
  25. }
  1. #language basic
  2. Dim i = 10
  3. if i = 1 then
  4.   alert("i=1")
  5. else
  6.   for i=0 to 10
  7.     select case i
  8.       case 1: echo(i+1)
  9.       case 2..10: echo(i)
  10.       case else: echo(i+10)
  11.     end select
  12.   next
  13.   do
  14.     echo(i)
  15.     i = i + 1
  16.   loop while i<20
  17. end if

第2课 - 请求网页 (Http Request URL)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin  
  3.    _GET.cookie  := 'a=1; ';
  4.    _GET.referer := 'http://www.baidu.com/';
  5.    content      := httpget('http://news.qq.com/a/20120424/000057.htm');
  6.    echo(content);
  7. end.
  1. #language js
  2. _GET.cookie = "a=1;";
  3. _GET.referer = "http://www.baidu.com/";
  4. content = httpget("http://news.qq.com/a/20120424/000057.htm");
  5. echo(content);
  1. #language c
  2. {
  3.    _GET.cookie = "a=1;";
  4.    _GET.referer = "http://www.baidu.com/";
  5.    content = httpget("http://news.qq.com/a/20120424/000057.htm");
  6.    echo(content);
  7. }
  1. #language basic
  2. _GET.referer = "http://www.baidu.com/"
  3. content = httpget("http://news.qq.com/a/20120424/000057.htm")
  4. echo(content)

第3课 - 智能分析新闻内容 (Analyze News Content)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. var content :string;
  3. begin
  4.    content := httpget('http://news.qq.com/a/20120424/000057.htm');
  5.    content := analyzecontent(content);
  6.    echo(content);
  7. end.
  1. #language js
  2. content = httpget("http://news.qq.com/a/20120424/000057.htm");
  3. content = analyzecontent(content);
  4. echo(content);
  1. #language c
  2. {
  3.    content = httpget("http://news.qq.com/a/20120424/000057.htm");
  4.    content = analyzecontent(content);
  5.    echo(content);
  6. }
  1. #language basic
  2. dim content
  3. content = httpget("http://news.qq.com/a/20120424/000057.htm")
  4. content = analyzecontent(content)
  5. echo(content)

第4课 - 下载文件(Download File)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin
  3.    httpget('http://www.google.com.hk/', '', 'c:/google.html');
  4. end.
  1. #language js
  2. httpget("http://www.google.com.hk/", "", "c:/google.html");
  1. #language c
  2. {
  3.    httpget("http://www.google.com.hk/", "", "c:/google.html");
  4. }
  1. #language basic
  2. httpget("http://www.google.com.hk/", "", "c:/google.html")

第5课 - 断点续传下载文件(Download File By Position)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. //Tip:1、Run 2、Stop 3、Resume Run
  3.  
  4. begin
  5.    httpdownload('http://21.duote.net/mozhua.zip', 'c:/mozhua.zip');
  6. end.
  1. #language js
  2. httpdownload("http://21.duote.net/mozhua.zip", "c:/mozhua.zip");
  1. #language c
  2. {
  3.    httpdownload("http://21.duote.net/mozhua.zip", "c:/mozhua.zip");
  4. }
  1. #language basic
  2. httpdownload("http://21.duote.net/mozhua.zip", "c:/mozhua.zip")

第6课 - Ini文件读写(Ini File)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. //saveini(FilePath:string;Section:string;KeyName:string;Value:string=''):String;
  3.  
  4. begin
  5.   saveini('save.ini', 'test', 'val', 'value');
  6.   echo(readini('save.ini', 'test', 'val', '1'));
  7. end.
  1. #language js
  2. saveini("save.ini", "test", "val", "value");
  3.   echo(readini("save.ini", "test", "val", "1"));
  1. #language c
  2. {
  3.   saveini("save.ini", "test", "val", "value");
  4.   echo(readini("save.ini", "test", "val", "1"));
  5. }
  1. #language basic
  2. saveini("save.ini", "test", "val", "value")
  3. echo(readini("save.ini", "test", "val", "1"))

第7课 - 数组(Array)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. var
  3.   arr1 : array[0..1] of string;
  4.   arr2 : array of string;
  5.   arr3 : Tinfo;
  6. begin
  7.   //array of static length
  8.   arr1[0] := 'string1';
  9.   arr1[1] := 'string2';
  10.   echo(arr1[0]);
  11.   //array of dynamic
  12.   setlength(arr2, 2);
  13.   arr2[0] := 'string1';
  14.   arr2[1] := 'string2';
  15.   echo(arr2[1]);
  16.   //Tinfo Object
  17.   arr3    := Tinfo.create;
  18.   arr3['index1'] := 'string1';
  19.   arr3['this is index'] := 'string2';
  20.   echo(arr3['this is index']);
  21.   //you can free this object or App Auto Free
  22.   arr3.free;
  23. end.
  1. #language js
  2. var arr[10],arr2;
  3.  
  4. for(var i = 0; i < 10; i++)
  5.   arr[i] = IntToStr(i);
  6.  
  7. var s = "";
  8. for(i = 0; i < 10; i++)
  9.   s += arr[i];
  10.  
  11. echo(s);
  12.  
  13. arr2 = new TInfo();
  14. arr2["index1"] = "string1";
  15. arr2["this is index"] = "string2";
  16. echo(arr2["this is index"]);
  1. #language c
  2. setlength(arr, 10);
  3.  
  4. for(int i = 0; i < 10; i++){
  5.   arr[i] = IntToStr(i);
  6. }
  7.  
  8. string s = "";
  9. for(i = 0; i < 10; i++)
  10.   s += arr[i];
  11.  
  12. echo(s);
  13.  
  14. arr2 = new TInfo();
  15. arr2["index1"] = "string1";
  16. arr2["this is index"] = "string2";
  17. echo(arr2["this is index"]);
  1. #language basic
  2. setlength(arr, 10)
  3. for i=0 to 9
  4.   arr[i] = inttostr(i)
  5. next
  6. echo(arr[0])
  7.  
  8. arr2 = new TInfo()
  9. arr2["index1"] = "string1"
  10. arr2["this is index"] = "string2"
  11. echo(arr2["this is index"])

第8课 - 文件操作(File Function)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. var
  3.    fileHandle : Integer;
  4. begin
  5.    //save/savefile is same function
  6.    save('abc.txt', 'this is test');
  7.    for i:=0 to 100 do
  8.    begin
  9.      //append string to a file
  10.      savefile('abc.txt', inttostr(i)+'.line'+#13#10, true);
  11.    end;
  12.    if isfile('abc.txt') then
  13.    begin
  14.      // fopen/fclose/fgets/fread,fseek,fwrite function same as php
  15.      fileHandle := fopen('abc.txt', 'r+');
  16.      while not feof(FileHandle) do
  17.      begin
  18.        //read one line
  19.        line := fgets(fileHandle);
  20.        echo(line);
  21.      end;  
  22.      fclose(fileHandle);
  23.    end;  
  24. end.
  1. #language js
  2. var i,fileHandle;        
  3.  
  4. //save/savefile is same function
  5.  
  6. save("abc.txt", "this is test");
  7.  
  8. for(i=0;i<=100;i++){
  9.   //append string to a file
  10.   savefile("abc.txt", inttostr(i)+".line"+chr(13)+chr(10), true);
  11. }
  12.  
  13. if(isfile("abc.txt")){
  14.   // fopen/fclose/fgets/fread,fseek,fwrite function same as php
  15.   fileHandle = fopen("abc.txt", "r+");
  16.   while(!feof(fileHandle)){
  17.     var line = fgets(fileHandle);
  18.     echo(line);
  19.   }
  20.   fclose(fileHandle);
  21. }
  1. #language c
  2. {
  3.   int i,fileHandle;        
  4.  
  5.   //save/savefile is same function
  6.  
  7.   save("abc.txt", "this is test");
  8.  
  9.   for(i=0;i<=100;i++){
  10.      //append string to a file
  11.     savefile("abc.txt", inttostr(i)+".line"+chr(13)+chr(10), true);
  12.   }
  13.   if(isfile("abc.txt")){
  14.     // fopen/fclose/fgets/fread,fseek,fwrite function same as php
  15.     fileHandle = fopen("abc.txt", "r+");
  16.     while(!feof(fileHandle)){
  17.       string line = fgets(fileHandle);
  18.       echo(line);
  19.     }
  20.     fclose(fileHandle);
  21.   }
  22. }
  1. #language basic
  2. Dim i,fileHandle,line        
  3.  
  4. 'save/savefile is same function
  5.  
  6. save("abc.txt", "this is test")
  7.  
  8. for i=0 to 100
  9.   'append string to a file
  10.   savefile("abc.txt", inttostr(i)+".line"+chr(13)+chr(10), true)
  11. next
  12.  
  13.  
  14. ' fopen/fclose/fgets/fread,fseek,fwrite function same as php
  15. if isfile("abc.txt") then
  16.   fileHandle = fopen("abc.txt", "r+")
  17.  
  18.   while not feof(fileHandle)
  19.     line = fgets(fileHandle)
  20.     echo(line)
  21.   wend      
  22.   fclose(fileHandle)
  23. end if

第9课 - 线程基本运用(Use Thread Base1)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. const
  3.       RunLang = '#language pascal'+#13#10+'begin'+#13#10+'%s'+#13#10+'end.';
  4.       EchoScript = 'echo(''i Was Run, My Name is:''+_ThreadName);';
  5. var
  6.       RunScript : string;
  7. begin    
  8.   RunScript := Format(RunLang, [EchoScript]);
  9.   //to see What Are We Run In Child Thread
  10.   {
  11.    #language pascal
  12.    begin
  13.      echo('i Was Run, My Name is:'+_ThreadName);
  14.    end.
  15.   }
  16.   echo(RunScript);
  17.   //Start Thread, First Param Can Pass Source Or FilePath.
  18.   RunThread(RunScript, 'EchoThread');
  19.   //wait EchoThread Execute Over;
  20.   waitThread('EchoThread');
  21.   //Or You Can wait All Thread Execute Over;
  22.   //waitThread;
  23. end.
  1. #language js
  2. var
  3.   RunLang = "#language js"+#13#10+"%s",
  4.   RunScript,
  5.   EchoScript = "echo(""i Was Run, My Name is:""+_ThreadName);";
  6.  
  7.   //to see What Are We Run In Child Thread
  8.   /*
  9.    #language js
  10.    echo("i Was Run, My Name is:"+_ThreadName);
  11.   */
  12.   RunScript = Format(RunLang, [EchoScript]);
  13.   echo(RunScript);    
  14.   //Start Thread, First Param Can Pass Source Or FilePath.
  15.   RunThread(RunScript, "EchoThread");
  16.   //wait EchoThread Run Over
  17.   waitThread("EchoThread");
  18.   //Or You Can wait All Thread Run Over;
  19.   //waitThread;
  1. #language c
  2. {
  3. string
  4.   RunLang = "#language c"+#13#10+"{"+#13#10+"%s"+#13#10+"}",
  5.   RunScript,
  6.   EchoScript = "echo(""i Was Run, My Name is:""+_ThreadName);";
  7.  
  8.   //to see What Are We Run In Child Thread
  9.   /*
  10.     #language c
  11.     {
  12.       echo("i Was Run, My Name is:"+_ThreadName);
  13.     }
  14.   */
  15.   RunScript = Format(RunLang, [EchoScript]);
  16.   echo(RunScript);    
  17.   //Start Thread, First Param Can Pass Source Or FilePath.
  18.   RunThread(EchoScript, "EchoThread");
  19.   //wait EchoThread Run Over
  20.   waitThread("EchoThread");
  21.   //Or You Can wait All Thread Run Over;
  22.   //waitThread;
  23. }
  1. #language basic
  2. Dim RunLang = "#language basic"+#13#10+"%s"
  3. Dim EchoScript = "echo(""i Was Run, My Name is:"" & _ThreadName)"  
  4. Dim RunScript = Format(RunLang, [EchoScript])
  5. 'to see What Are We Run In Child Thread
  6. '--------------------------------------------
  7. '#language basic
  8. 'echo("i Was Run, My Name is:" & _ThreadName)
  9. '--------------------------------------------
  10. echo(RunScript)
  11.  
  12. 'Start Thread, First Param Can Pass Source Or FilePath.
  13. RunThread(EchoScript, "EchoThread")
  14.  
  15. 'wait EchoThread Run Over
  16. waitThread("EchoThread")
  17.  
  18. 'Or You Can wait All Thread Run Over;
  19. 'waitThread()

第10课 - 线程基本运用2(Use Thread Base2)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. const
  3.   RunLang = '#language pascal'+#13#10+'begin'+#13#10+'%s'+#13#10+'end.';
  4.   VarScript = 'str1 := ''my vars is ''+passstr;'+#13#10+'str2 := ''my name is ''+_ThreadName;';
  5. var
  6.   RunScript : string;
  7.  
  8. //CallBack When A Thread Start Execute
  9. //TDoscripter is Thread Object  
  10. procedure OnThreadStart(Doscript:TDoscripter);
  11. begin
  12.   if DoScript['_ThreadName'] = 'EchoThread' then
  13.   begin
  14.     //pass a variaible value is 'ok'  
  15.     DoScript['passstr'] := 'ok';
  16.   end
  17.   else begin      
  18.     //pass a variaible value is 'other'  
  19.     DoScript['passstr'] := 'other';
  20.   end;
  21. end;
  22.  
  23. //CallBack When A Thread Execute Over
  24. //TDoscripter is Thread Object
  25. procedure OnThreadOver(DoScript:TDoscripter);
  26. begin
  27.   //access variaible In Thread
  28.   Echo(DoScript['str1']);
  29.   Echo(DoScript['str2']);
  30. end;
  31.  
  32.  
  33. begin    
  34.   RunScript := Format(RunLang, [VarScript]);
  35.   //to see What Are We Run In Child Thread
  36.   {
  37.    #language pascal
  38.    begin
  39.      str1 := 'my vars is '+passstr;
  40.      str2 := 'my name is '+_ThreadName;
  41.    end.
  42.   }
  43.   //Start Thread 1 , First Param Can Pass Source Or FilePath.
  44.   RunThread(RunScript, 'EchoThread', 'OnThreadStart', 'OnThreadOver');
  45.   //Start Thread 2 , OnThreadStart Pass Another variaible To Do
  46.   RunThread(RunScript, 'Thread2', 'OnThreadStart', 'OnThreadOver');
  47.   //Wait All Thread Execute
  48.   waitThread;
  49. end.
  1. #language js
  2. var RunLang = "#language js"+chr(13)+chr(10)+"%s";
  3. var VarScript = "str1 = ""my vars is ""+passstr;"+chr(13)+chr(10)+"str2 = ""my name is ""+_ThreadName;";
  4. var RunScript;
  5.  
  6. //CallBack When A Thread Start Execute
  7. //TDoscripter is Thread Object  
  8. function OnThreadStart(Doscript){
  9.   if(DoScript["_ThreadName"]=="EchoThread"){
  10.     //pass a variaible value "ok"
  11.     DoScript["passstr"] = "ok";
  12.   }else{        
  13.     //pass a variaible  value "other"  
  14.     DoScript["passstr"] = "other";
  15.   }
  16. }
  17.  
  18. //CallBack When A Thread Execute Over
  19. //TDoscripter is Thread Object    
  20. function OnThreadOver(Doscript){
  21.   //access variaible In Thread
  22.   Echo(DoScript["str1"]);
  23.   Echo(DoScript["str2"]);
  24. }
  25.  
  26. //main
  27. RunScript = Format(RunLang, [VarScript]);
  28. //to see What Are We Run In Child Thread
  29. /*
  30.   #language js
  31.   str1 = "my vars is "+passstr;
  32.   str2 = "my name is "+_ThreadName;
  33. */
  34. //Start Thread 1 , First Param Can Pass Source Or FilePath.
  35. RunThread(RunScript, "EchoThread", "OnThreadStart", "OnThreadOver");
  36. //Start Thread 2 , OnThreadStart Pass Another variaible To Do
  37. RunThread(RunScript, "Thread2", "OnThreadStart", "OnThreadOver");
  38. //Wait All Thread Execute
  39. waitThread;
  1. #language c
  2. string RunLang = "#language c"+chr(13)+chr(10)+"{"+chr(13)+chr(10)+"%s"+chr(13)+chr(10)+"}";
  3. string VarScript = "str1 = ""my vars is ""+passstr;"+chr(13)+chr(10)+"str2 = ""my name is ""+_ThreadName;";
  4. string RunScript;
  5.  
  6. //CallBack When A Thread Start Execute
  7. //TDoscripter is Thread Object  
  8. int OnThreadStart(TDoscripter Doscript){
  9.   if(DoScript["_ThreadName"]=="EchoThread"){
  10.     //pass a variaible value "ok"
  11.     DoScript["passstr"] = "ok";
  12.   }else{        
  13.     //pass a variaible  value "other"  
  14.     DoScript["passstr"] = "other";
  15.   }
  16. }
  17.  
  18. //CallBack When A Thread Execute Over
  19. //TDoscripter is Thread Object    
  20. int OnThreadOver(TDoscripter Doscript){
  21.   //access variaible In Thread
  22.   Echo(DoScript["str1"]);
  23.   Echo(DoScript["str2"]);
  24. }
  25.  
  26.  
  27. //main
  28. {
  29.   RunScript = Format(RunLang, [VarScript]);
  30.   //to see What Are We Run In Child Thread
  31.   /*
  32.    #language c
  33.    {
  34.      str1 := "my vars is "+passstr;
  35.      str2 := "my name is "+_ThreadName;
  36.    }
  37.   */
  38.   //Start Thread 1 , First Param Can Pass Source Or FilePath.
  39.   RunThread(RunScript, "EchoThread", "OnThreadStart", "OnThreadOver");
  40.   //Start Thread 2 , OnThreadStart Pass Another variaible To Do
  41.   RunThread(RunScript, "Thread2", "OnThreadStart", "OnThreadOver");
  42.   //Wait All Thread Execute
  43.   waitThread;
  44.  
  45. }
  1. #language basic
  2. Dim CrLf    = chr(13)+chr(10)
  3. Dim Qt      = chr(34)
  4. Dim RunLang = "#language js" +CrLf
  5. Dim VarScript = "str1 = "& Qt &"my vars is "& Qt &"+passstr"+CrLf+"str2 = "& Qt &"my name is "& Qt &"+_ThreadName"  
  6. Dim RunScript =  RunLang + VarScript
  7.  
  8. function OnThreadStart(Doscript)
  9.   if DoScript["_ThreadName"]="EchoThread" then
  10.     'pass a variaible value "ok"
  11.     DoScript["passstr"] = "ok"
  12.   else
  13.     'pass a variaible  value "other"  
  14.     DoScript["passstr"] = "other"
  15.   end if
  16. end Function
  17.  
  18. function OnThreadOver(Doscript)
  19.   'access variaible In Thread
  20.   Echo(DoScript["str1"])
  21.   Echo(DoScript["str2"])
  22. end Function
  23.  
  24. 'to see What Are We Run In Child Thread
  25. '------------------------------------
  26. '#language js
  27. 'str1 = "my vars is "+passstr
  28. 'str2 = "my name is "+_ThreadName    
  29. '------------------------------------
  30. 'echo(RunScript)
  31.  
  32. 'Start Thread 1 , First Param Can Pass Source Or FilePath.
  33. RunThread(RunScript, "EchoThread", "OnThreadStart", "OnThreadOver")
  34. 'Start Thread 2 , OnThreadStart Pass Another variaible To Do
  35. RunThread(RunScript, "Thread2", "OnThreadStart", "OnThreadOver")
  36.  
  37. 'Wait All Thread Execute
  38. waitThread

第11课 - 提取百度新闻(Match Baidu News)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. procedure getnews(Reg:TRegexp;Matchstr:string;Params:variant);
  3. begin
  4.    //html to txt
  5.    title := html2txt(Reg['title']);
  6.    desc  := html2txt(Reg['desc']);
  7.    echo(title+':'+desc);
  8. end;
  9.  
  10. begin
  11.    //download url source
  12.    html := httpget('http://news.baidu.com/ns?word=%B1%B1%BE%A9');
  13.    //RegCallback
  14.    RegCallBack('getnews', html, '<h3 class="c-title">(?<title>[\s\S]*?)</a>[\s\S]*?<div class="c-summary">(?<desc>[\s\S]*?)<a href');
  15. end.
  1. #language js
  2. function getnews(Reg, Matchstr,Params){
  3.    //html to txt
  4.    title = html2txt(Reg["title"]);
  5.    desc  = html2txt(Reg["desc"]);
  6.    echo(title+":"+desc);
  7. }
  8. //main
  9. //download url source
  10. var html = httpget("http://news.baidu.com/ns?word=%B1%B1%BE%A9");
  11. //RegCallback
  12. RegCallBack("getnews", html, "<h3 class=""c-title"">(?<title>[\s\S]*?)</a>[\s\S]*?<div class=""c-summary"">(?<desc>[\s\S]*?)<a href");
  1. #language c
  2. int getnews(TRegexp Reg, String Matchstr,Variant Params){
  3.    //html to txt
  4.    title = html2txt(Reg["title"]);
  5.    desc  = html2txt(Reg["desc"]);
  6.    echo(title+":"+desc);
  7. }
  8. //main
  9. {
  10.   //download url source
  11.   html = httpget("http://news.baidu.com/ns?word=%B1%B1%BE%A9");
  12.   //
  13.   RegCallBack("getnews", html, "<h3 class=""c-title"">(?<title>[\s\S]*?)</a>[\s\S]*?<div class=""c-summary"">(?<desc>[\s\S]*?)<a href");
  14.  
  15. }
  1. #language basic
  2. function getnews(Reg, Matchstr, params)
  3.    'html to txt
  4.    title = html2txt(Reg["title"])
  5.    desc  = html2txt(Reg["desc"])
  6.    echo(title & ":" & desc)
  7. end function
  8.  
  9. 'main
  10. 'download url source
  11. html = httpget("http://news.baidu.com/ns?word=%B1%B1%BE%A9")
  12. 'RegCallback
  13. RegCallBack("getnews", html, "<h3 class=""c-title"">(?<title>[\s\S]*?)</a>[\s\S]*?<div class=""c-summary"">(?<desc>[\s\S]*?)<a href")

第12课 - 分析下载小说(Get Chapter Content)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. //set default content url
  3. var
  4.     URL :string = 'http://www.biquge.com/0_360/157143.html';
  5.  
  6. begin
  7.   Title := '';
  8.   while URL <>'' do
  9.   begin
  10.      //download the URL
  11.      httpget(URL);
  12.      if _GET.ResponseCode = 200 then
  13.      begin
  14.       //Match Cotent By Pattern
  15.        Content := Match(_GET.HTML, '<div id="content">(*)</div>');
  16.        //HTML Convert Text Format;
  17.        Content := Html2txt(Content);
  18.        //Match Next Page URL, And Convert Absolute Url
  19.        //MatchURL Where innerText is '下一章'
  20.        URL := MatchURL(_GET.HTML, URL, '{:text,下一章}');
  21.      
  22.        //Next Page Check Format
  23.        if Pos('index', URL)>0 then break;
  24.      
  25.        //Get Content Title
  26.        if Title = '' then
  27.        begin
  28.           //Match Title
  29.           Title := match(_GET.HTML, 'var booktitle = "(*)"');
  30.           //Replace FileName Bad Chars
  31.           Title := replaceFileNamechars(Title);
  32.           //Clear Old File Content
  33.           SaveFile(Title+'.txt', '');
  34.        end;
  35.        //append Txt File Content
  36.        SaveFile(Title+'.txt', Content, true);
  37.        //File Was Saved in The Script Directory
  38.      
  39.        //and to do another thing...
  40.      
  41.        //Show Progress
  42.        if URL<>'' then
  43.          echo('Download Next Chapter:'+URL);
  44.      end;
  45.   end;
  46. end.
  1. #language js
  2. //set default content url
  3. var URL = "http://www.biquge.com/0_360/157143.html",
  4.     Title = "";
  5.  
  6. while(URL !=""){
  7.    //download the URL
  8.    httpget(URL);
  9.    if(_GET.ResponseCode == 200){
  10.      //Match Cotent By Pattern
  11.      Content = Match(_GET.HTML, "<div id=""content"">(*)</div>");
  12.      //HTML Convert Text Format;
  13.      Content = Html2txt(Content);
  14.      //Match Next Page URL, And Convert Absolute Url
  15.      //MatchURL Where innerText is '下一章'
  16.      URL = MatchURL(_GET.HTML, URL, "{:text,下一章}");
  17.    
  18.      //Next Page Check Format
  19.      if(Pos("index", URL)>0){
  20.        break;
  21.      }
  22.      //Get Content Title
  23.      if(Title==""){
  24.         //Match Title
  25.         Title = match(_GET.HTML, "var booktitle = ""(*)""");
  26.         //Replace FileName Bad Chars
  27.         Title = replaceFileNamechars(Title);
  28.         //Clear Old File Content
  29.         SaveFile(Title+".txt", "");
  30.      }
  31.      //append Txt File Content
  32.      SaveFile(Title+".txt", Content, true);
  33.      //File Was Saved in The Script Directory
  34.    
  35.      //and to do another thing...
  36.    
  37.      //Show Progress
  38.      if(URL!=""){
  39.        echo("Download Next Chapter:"+URL);
  40.      }
  41.    }
  42. }
  1. #language c
  2. //set default content url
  3. string URL = "http://www.biquge.com/0_360/157143.html";
  4. string Title = "";
  5.  
  6. {
  7.   while(URL !=""){
  8.      //download the URL
  9.      httpget(URL);
  10.      if(_GET.ResponseCode == 200){
  11.        //Match Cotent By Pattern
  12.        Content = Match(_GET.HTML, "<div id=""content"">(*)</div>");
  13.        //HTML Convert Text Format;
  14.        Content = Html2txt(Content);
  15.        //Match Next Page URL, And Convert Absolute Url
  16.        //MatchURL Where innerText is '下一章'
  17.        URL = MatchURL(_GET.HTML, URL, "{:text,下一章}");
  18.      
  19.        //Next Page Check Format
  20.        if(Pos("index", URL)>0){
  21.          break;
  22.        }
  23.        //Get Content Title
  24.        if(Title==""){
  25.           //Match Title
  26.           Title = match(_GET.HTML, "var booktitle = ""(*)""");
  27.           //Replace FileName Bad Chars
  28.           Title = replaceFileNamechars(Title);
  29.           //Clear Old File Content
  30.           SaveFile(Title+".txt", "");
  31.        }
  32.        //append Txt File Content
  33.        SaveFile(Title+".txt", Content, true);
  34.        //File Was Saved in The Script Directory
  35.      
  36.        //and to do another thing...
  37.      
  38.        //Show Progress
  39.        if(URL!=""){
  40.          echo("Download Next Chapter:"+URL);
  41.        }
  42.      }
  43.   }
  44. }
  1. #language basic
  2. Dim URL = "http://www.biquge.com/0_360/157143.html"
  3. Dim Title = ""
  4.  
  5. while URL<>""
  6.    'download the URL
  7.    httpget(URL)
  8.    if GET.ResponseCode = 200 then
  9.      'Match Cotent By Pattern
  10.      Content = Match(GET.HTML, "<div id=""content"">(*)</div>")
  11.      'HTML Convert Text Format;
  12.      Content = Html2txt(Content)
  13.      'Match Next Page URL, And Convert Absolute Url
  14.      'MatchURL Where innerText is '下一章'
  15.      URL = MatchURL(GET.HTML, URL, "{:text,下一章}")
  16.  
  17.      'Next Page Check Format
  18.      if(Pos("index", URL)>0)then
  19.        break
  20.      end if
  21.      'Get Content Title
  22.      if(Title="")then
  23.         'Match Title
  24.         Title = match(GET.HTML, "var booktitle = ""(*)""")
  25.         'Replace FileName Bad Chars
  26.         Title = replaceFileNamechars(Title)
  27.         'Clear Old File Content
  28.         SaveFile(Title+".txt", "")
  29.      end if
  30.      'append Txt File Content
  31.      SaveFile(Title+".txt", Content, true)
  32.      'File Was Saved in The Script Directory
  33.    
  34.      'and to do another thing...
  35.    
  36.      'Show Progress
  37.      if URL<>"" then
  38.        echo("Download Next Chapter:"+URL)
  39.      end if
  40.    end if
  41. wend

第13课 - 天涯帖子脱水机(Get Content From Tianya.cn)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. var
  3.     ids : array of string;
  4.     author,sfile,title:string;
  5.  
  6. function getcontent(html:string;pageone:boolean=false):string;
  7. begin
  8.     repeat
  9.         //取帖子内容
  10.         body := match(html, author+'</a>(*)<div class="post-jb"></div>');
  11.         if(body<>'')then
  12.         begin
  13.             //保存
  14.             savefile(sfile, html2txt(body)+#13#10, true);
  15.         end;
  16.         //去除当前的内容,再匹配一次
  17.         html := copy(html, pos(body, html)+length(body), MAXINT);
  18.     until body = '';
  19. end;
  20.  
  21. begin
  22.    
  23.     try
  24.         url := input('请输入您要下载天涯帖的地址','URL','http://www.tianya.cn/publicforum/content/culture/1/343346.shtml');
  25.     except
  26.     end;
  27.     if url = null then exit;
  28.     //下载首页
  29.     echo('开始下载处理首页:'+url);
  30.     html := httpget(url);
  31.     //
  32.     ids  := split(match(html, 'idArticleslist[*]value="(*),"'), ',');
  33.     //页数
  34.     pgs  := length(ids);
  35.  
  36.     //取得楼主的信息
  37.     author := match(html, 'chrAuthorName = "(*)";');
  38.     title  := html2txt(match(html, 'chrTitle = "(*)";'));
  39.     sfile  := _path(0)+'download/'+replacefilenamechars(title)+'.txt';
  40.    
  41.     //取得第一页内容
  42.     getcontent(html, true);
  43.     //
  44.     echo(title+':取得共有 '+inttostr(pgs)+' 页需要处理...');
  45.    
  46.     //从第二页开始取内容
  47.     for i:=1 to pgs - 1 do
  48.     begin
  49.         _url := regreplace(url, '\d+\.shtml', ids[i]+'.shtml');
  50.         echo(title+':开始下载第'+inttostr(i+1)+'/'+inttostr(pgs)+'页:'+_url);
  51.         //清除缓存
  52.         _GET.clear;
  53.         html := httpget(_url);
  54.         getcontent(html, false);
  55.     end;
  56.     //保存
  57.     savefile(sfile, #13#10+'本内容由Doscripter整理,更多好玩的请上魔爪社区:www.mozhua.net', true);
  58.     echo('下载完毕:'+sfile);
  59.     //运行该下载后的txt文件
  60.     run(sfile);
  61. end.
  1. #language js
  2. var author='';
  3. var sfile='';
  4. var title='';
  5.  
  6. function getcontent(html, pageone){
  7.        for(body = match(html, author+'</a>(*)<div class="post-jb"></div>');
  8.            body != '' ;){
  9.            if(body!=''){
  10.               //保存
  11.               savefile(sfile, html2txt(body)+chr(13)+chr(10), true);
  12.            }    
  13.            //delete match body
  14.            html = copy(html, pos(body, html)+length(body), MAXINT);
  15.            if(html=='')break;
  16.        }
  17. }
  18. //main
  19. url = input('请输入您要下载天涯帖的地址','URL','http://www.tianya.cn/publicforum/content/culture/1/343346.shtml');
  20. if(url == null){
  21.   exit;
  22. }
  23. //下载首页
  24. echo('开始下载处理首页:'+url);
  25. html = httpget(url);
  26. //取得所有page
  27. ids  = split(match(html, 'idArticleslist[*]value="(*),"'), ',');    
  28. //页数
  29. pgs  = length(ids);      
  30. //取得楼主的信息
  31. author = match(html, 'chrAuthorName = "(*)";');
  32. title  = html2txt(match(html, 'chrTitle = "(*)";'));
  33. sfile  = _path(0)+'download/'+replacefilenamechars(title)+'.txt';
  34. //取得第一页内容
  35. getcontent(html, true);
  36. //输出进度
  37. echo(title+':取得共有 '+inttostr(pgs)+' 页需要处理...');
  38. //从第二页开始取内容
  39. for(i=1;i<pgs;i++){
  40.   _url = regreplace(url, '\d+\.shtml', ids[i]+'.shtml');
  41.   echo(title+':开始下载第'+inttostr(i+1)+'/'+inttostr(pgs)+'页:'+_url);
  42.   //清除缓存
  43.   _GET.clear;
  44.   html = httpget(_url);
  45.   getcontent(html, false);
  46. }
  47. //保存
  48. savefile(sfile, chr(13)+chr(10)+'本内容由Doscripter整理,更多好玩的请上魔爪社区:www.mozhua.net', true);
  49. echo('下载完毕:'+sfile);
  50. //运行该下载后的txt文件
  51. run(sfile);
  1. #language c
  2. string author='';
  3. string sfile='';
  4. string title='';
  5.  
  6. int getcontent(string html, boolean pageone=false){
  7.        for(body = match(html, author+'</a>(*)<div class="post-jb"></div>');
  8.            body != '' ;){
  9.            if(body!=''){
  10.               //保存
  11.               savefile(sfile, html2txt(body)+chr(13)+chr(10), true);
  12.            }    
  13.            //delete match body
  14.            html = copy(html, pos(body, html)+length(body), MAXINT);
  15.            if(html=='')break;
  16.        }
  17. }
  18. //main
  19. {
  20.   url = input('请输入您要下载天涯帖的地址','URL','http://www.tianya.cn/publicforum/content/culture/1/343346.shtml');
  21.   if(url == null){
  22.     exit;
  23.   }
  24.   //下载首页
  25.   echo('开始下载处理首页:'+url);
  26.   html = httpget(url);
  27.   //取得所有page
  28.   ids  = split(match(html, 'idArticleslist[*]value="(*),"'), ',');    
  29.   //页数
  30.   pgs  = length(ids);      
  31.   //取得楼主的信息
  32.   author = match(html, 'chrAuthorName = "(*)";');
  33.   title  = html2txt(match(html, 'chrTitle = "(*)";'));
  34.   sfile  = _path(0)+'download/'+replacefilenamechars(title)+'.txt';
  35.   //取得第一页内容
  36.   getcontent(html, true);
  37.   //输出进度
  38.   echo(title+':取得共有 '+inttostr(pgs)+' 页需要处理...');
  39.   //从第二页开始取内容
  40.   for(i=1;i<pgs;i++){
  41.     _url = regreplace(url, '\d+\.shtml', ids[i]+'.shtml');
  42.     echo(title+':开始下载第'+inttostr(i+1)+'/'+inttostr(pgs)+'页:'+_url);
  43.     //清除缓存
  44.     _GET.clear;
  45.     html = httpget(_url);
  46.     getcontent(html, false);
  47.   }
  48.   //保存
  49.   savefile(sfile, chr(13)+chr(10)+'本内容由Doscripter整理,更多好玩的请上魔爪社区:www.mozhua.net', true);
  50.   echo('下载完毕:'+sfile);
  51.   //运行该下载后的txt文件
  52.   run(sfile);
  53. }
  1. #language basic
  2. Dim author=""
  3. Dim sfile=""
  4. Dim title=""
  5. Dim i = 1
  6.  
  7. function getcontent(html, pageone)
  8.   do
  9.     body = match(html, author+"</a>(*)<div class=""post-jb""></div>")
  10.     if body <> "" then
  11.       '保存
  12.       savefile(sfile, html2txt(body)+chr(13)+chr(10), true)
  13.     end if
  14.    
  15.     'delete match body
  16.     html = copy(html, pos(body, html)+length(body), MAXINT)
  17.     if html = "" then
  18.        break
  19.     end if
  20.   loop while (html = "")OR(body = "")
  21. end function
  22.  
  23. 'main
  24. url = input("请输入您要下载天涯帖的地址","URL","http://www.tianya.cn/publicforum/content/culture/1/343346.shtml")
  25. if url = null then
  26.   exit
  27. end if
  28. '下载首页
  29. echo("开始下载处理首页:"+url)
  30. html = httpget(url)
  31.  
  32. '取得所有page
  33. ids  = split(match(html, "idArticleslist[*]value=""(*),"""), ",")  
  34. '页数
  35. pgs  = length(ids)      
  36. '取得楼主的信息
  37. author = match(html, "chrAuthorName = ""(*)"";")
  38. title  = html2txt(match(html, "chrTitle = ""(*)"";"))
  39. sfile  = call("_path", 0) + "download/" + replacefilenamechars(title)+".txt"
  40. '取得第一页内容
  41. getcontent(html, true)
  42. '输出进度
  43. echo(title+":取得共有 "+inttostr(pgs)+" 页需要处理...")
  44. '从第二页开始取内容
  45. for i=1 to pgs-1
  46.   surl = regreplace(url, "\d+\.shtml", ids[i]+".shtml")
  47.   echo(title+":开始下载第"+inttostr(i+1)+"/"+inttostr(pgs)+"页:"+surl)
  48.   html = httpget(surl)
  49.   getcontent(html, false)
  50. next
  51. '保存
  52. savefile(sfile, chr(13)+chr(10)+"本内容由Doscripter整理,更多好玩的请上魔爪社区:www.mozhua.net", true)
  53. echo("下载完毕:"+sfile)
  54. '运行该下载后的txt文件
  55. run(sfile)

第14课 - _GET对象的使用(The "_GET" objects of use)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin
  3.     _GET.Clear;
  4.     _GET.UserAgent  := 'UA';
  5.     _GET.Accept     := '*/*';
  6.     _GET.Referer    := 'http://www.baidu.com/';
  7.     _GET.URL        := 'http://www.google.com/';
  8.     _GET.cookie     := 'a=b; c=1';
  9.     httpget('http://www.google.com.hk/intl/zh-CN/images/logo_cn.png');
  10.     echo('FORMAT:'+_GET.Format);
  11.     echo('Cookie:'+_GET.Cookie);
  12.  
  13.     _GET.Clear;
  14.     httpget('http://www.google.com.hk/');
  15.     if (_GET.ResponseCode = 200) then
  16.     begin
  17.       echo('HTML:'+_GET.HTML);
  18.       echo('RESPONSEHEAD:'+_GET.ResponseHead['']);
  19.     end;  
  20. end.
  1. #language js
  2. _GET.Clear;
  3. _GET.UserAgent  = 'UA';
  4. _GET.Accept     = '*/*';
  5. _GET.Referer    = 'http://www.baidu.com/';
  6. _GET.URL        = 'http://www.google.com/';
  7. _GET.cookie     = 'a=b; c=1';
  8. httpget('http://www.google.com.hk/intl/zh-CN/images/logo_cn.png');
  9. echo('FORMAT:'+_GET.Format);
  10. echo('Cookie:'+_GET.Cookie);
  11.  
  12. _GET.Clear;
  13. httpget('http://www.google.com.hk/')
  14. if(_GET.ResponseCode = 200){
  15.   echo('HTML:'+_GET.HTML);
  16.   echo('RESPONSEHEAD:'+_GET.ResponseHead['']);
  17. }
  1. #language c
  2. {
  3.     _GET.Clear;
  4.     _GET.UserAgent  = 'UA';
  5.     _GET.Accept     = '*/*';
  6.     _GET.Referer    = 'http://www.baidu.com/';
  7.     _GET.URL        = 'http://www.google.com/';
  8.     _GET.cookie     = 'a=b; c=1';
  9.     httpget('http://www.google.com.hk/intl/zh-CN/images/logo_cn.png');
  10.     echo('FORMAT:'+_GET.Format);
  11.     echo('Cookie:'+_GET.Cookie);
  12.  
  13.     _GET.Clear;
  14.     httpget('http://www.google.com.hk/')
  15.     if(_GET.ResponseCode = 200){
  16.       echo('HTML:'+_GET.HTML);
  17.       echo('RESPONSEHEAD:'+_GET.ResponseHead['']);
  18.     }
  19. }
  1. #language basic
  2. GET.Clear
  3. GET.UserAgent   = "UA"
  4. GET.Accept      = "*/*"
  5. GET.Referer     = "http://www.baidu.com/"
  6. GET.URL         = "http://www.google.com/"
  7. GET.cookie      = "a=b; c=1"
  8. httpget("http://www.google.com.hk/intl/zh-CN/images/logo_cn.png")
  9. echo("FORMAT:"+GET.Format)
  10. echo("Cookie:"+GET.Cookie)
  11.  
  12. GET.Clear
  13. httpget("http://www.google.com.hk/")
  14. if (GET.ResponseCode = 200) then
  15.   echo("HTML:"+GET.HTML)
  16.   echo("RESPONSEHEAD:"+GET.ResponseHead[""])
  17. end if

第15课 - 百度图片高清图片下载器(Baidu HD Image Download)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. //定义搜索关键字
  3. var
  4.    keyword  :string = '高圆圆';
  5. //默认保存图片路径
  6.    savepath :string = 'baiduImage/';
  7. //最大获取张数
  8.    maxnum   :integer = 200;
  9. //百度图片搜索接口
  10.    url :string = 'http://pic.baidu.com/i?tn=resultjson_com&sf=2&fmq=&istype=2&word=[[key]]&f=3&oe=utf-8&rn=60&pn=[[page]]';
  11. //百度识图签名接口
  12.    stuindex :string= 'http://stu.baidu.com/i?objurl=[[url]]&filename=&rt=0&rn=10&ftn=searchstu&ct=1&stt=0&tn=shituresult';
  13. //百度识图图片接口
  14.    stuurl :string = 'http://stu.baidu.com/i?dispView=imgView&sort=size&ct=3&querysign=[[query]]&objURL=[[url]]&bdTag=1&tn=shitujson&rn=60&pn=0';
  15.  
  16. //初始函数,设置refer地址,UA,cookie
  17. procedure initGet();
  18. begin
  19.     _GET.clear;
  20.     _GET.referer   := 'http://pic.baidu.com/';
  21.     _GET.useragent := 'Mozilla/5.0 (Windows NT 6.1; WOW64)';
  22.     _GET.cookie    := 'BAIDUID=B8F06EA0EBC15B615BD41688D47'+inttostr(rand(10, 99999))+':FG=1';
  23. end;
  24. //根据图片地址保存图片
  25. procedure getImgUrl(r:TRegexp;m:string);
  26. var
  27.     picfile : string;
  28.     newurl,sign,detailpic : string;
  29. begin
  30.     //根据关键字和MD5命名图片
  31.     picfile := keyword+'_'+md5(r['img'], 16)+'.jpg';
  32.     //初始化
  33.     initGet();
  34.     //根据传入的图片地址,替换识图签名中的变量
  35.     newurl  := replace(stuindex, '[[url]]', urlencode(r['img']));
  36.     //清空get对象
  37.     _GET.clear;
  38.     //调用识图签名接口
  39.     httpget(newurl);
  40.     //通过正则过滤GET对象中302地址的querysign参数
  41.     sign := Match(_GET.URL, 'querysign=(*)&');
  42.     //将地址替换识图图片接口中的url变量
  43.     picurl := replace(stuurl, '[[url]]',urlencode(r['img']));
  44.     //将签名替换识图接口中的query变量
  45.     picurl := replace(picurl, '[[query]]',sign);
  46.     //清空get对象
  47.     _GET.clear;
  48.     //用utf-8格式调用识图接口
  49.     httpget(picurl,'utf-8');
  50.     //将GET对象返回的HTML源码进行正则过滤
  51.     detailpic := Match(_GET.HTML,'"objURLEnc":"(*)"');
  52.     //获取图片地址,保存到定义的路径
  53.     httpget(detailpic, '', savepath+picfile);
  54.     //输出保存的图片地址用作进程输出
  55.     echo(detailpic);
  56.     //停止一秒
  57.     sleep(1000);
  58. end;
  59.  
  60.  
  61. begin
  62.     //保存地址为当前路径+初始定义路径
  63.     savepath := _path()+savepath;            
  64.     //检查是否为文件夹
  65.     isdir(savepath, true);                    
  66.     //将定义的关键词进行url转码替换百度搜索接口中的变量key
  67.     url := replace(url, '[[key]]', urlencode(keyword, true));
  68.     //设置每页数量                
  69.     persize := 60;
  70.     //用最大数量除每页数量向上取整,获得当前第几页
  71.     pages   := ceil(maxnum / persize);        
  72.     //进行循环调取
  73.         for index := 1 to pages do
  74.         begin                      
  75.            //替换page参数
  76.         trueurl := replace(url, '[[page]]', inttostr((index-1) * persize));
  77.         //初始化
  78.         initGet;
  79.         //调用搜索接口
  80.         httpget(trueurl, 'utf-8');
  81.         //将接口返回内容进行正则过滤后,回传给getImgUrl方法
  82.         regpick('getImgUrl', _GET.HTML, '/largeTnImageUrl":"(?<img>[^"]*?)"/is');
  83.         sleep(5000);  
  84.         end;
  85. end.
  1. #language js
  2. /*
  3. 原理为先调用百度搜索接口,获取图片地址
  4. 根据图片地址再调用百度识图接口,获取同样一张图尺寸最大的一张高清图
  5. */
  6. var
  7.     //定义搜索关键字
  8.     keyword = '高圆圆',
  9.     //默认保存图片路径
  10.     savepath = 'baiduImage/',
  11.     //最大获取张数
  12.     maxnum = 200,
  13.     //百度图片搜索接口
  14.     url = 'http://pic.baidu.com/i?tn=resultjson_com&sf=2&fmq=&istype=2&word=[[key]]&f=3&oe=utf-8&rn=60&pn=[[page]]',
  15.     //百度识图签名接口
  16.     stuindex = 'http://stu.baidu.com/i?objurl=[[url]]&filename=&rt=0&rn=10&ftn=searchstu&ct=1&stt=0&tn=shituresult',
  17.     //百度识图图片接口
  18.     stuurl = 'http://stu.baidu.com/i?dispView=imgView&sort=size&ct=3&querysign=[[query]]&objURL=[[url]]&bdTag=1&tn=shitujson&rn=60&pn=0';
  19.  
  20. //初始函数,设置refer地址,UA,cookie
  21. function initGet(){
  22.      _GET.clear;
  23.      _GET.referer = 'http://pic.baidu.com/';
  24.      _GET.useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64)';
  25.      _GET.cookie    = 'BAIDUID=B8F06EA0EBC15B615BD41688D47'+inttostr(rand(10, 99999))+':FG=1';
  26. }
  27. //根据图片地址保存图片
  28. function getImgUrl(r,m){
  29.     //根据关键字和MD5命名图片
  30.     var picfile = keyword+'_'+md5(r['img'], 16)+'.jpg';
  31.     //初始化
  32.     initGet();
  33.     //根据传入的图片地址,替换识图签名中的变量
  34.     newurl=replace(stuindex, '[[url]]', urlencode(r['img']));
  35.     //清空get对象
  36.     _GET.clear;
  37.     //调用识图签名接口
  38.     httpget(newurl);
  39.     //通过正则过滤GET对象中302地址的querysign参数
  40.     sign= Match(_GET.URL, 'querysign=(*)&');
  41.     //将地址替换识图图片接口中的url变量
  42.     picurl = replace(stuurl, '[[url]]',urlencode(r['img']));
  43.     //将签名替换识图接口中的query变量
  44.     picurl = replace(picurl, '[[query]]',sign);
  45.     //清空get对象
  46.     _GET.clear;
  47.     //用utf-8格式调用识图接口
  48.     httpget(picurl,'utf-8');
  49.     //将GET对象返回的HTML源码进行正则过滤
  50.     detailpic=Match(_GET.HTML,'"objURLEnc":"(*)"');
  51.     //获取图片地址,保存到定义的路径
  52.     httpget(detailpic, '', savepath+picfile);
  53.     //输出保存的图片地址用作进程输出
  54.     echo(detailpic);
  55.     //停止一秒
  56.     sleep(1000);
  57. }
  58. //保存地址为当前路径+初始定义路径
  59. savepath = _path()+savepath;
  60. //检查是否为文件夹
  61. isdir(savepath, true);
  62. //将定义的关键词进行url转码替换百度搜索接口中的变量key
  63. url = replace(url, '[[key]]', urlencode(keyword, true));
  64. //设置每页数量                
  65. persize = 60;
  66. //用最大数量除每页数量向上取整,获得当前第几页
  67. pages   = ceil(maxnum / persize);
  68. //进行循环调取
  69. for(var index=1;index<=pages;index++){
  70.     //替换page参数
  71.     trueurl = replace(url, '[[page]]', inttostr((index-1) * persize));
  72.     //初始化
  73.     initGet;
  74.     //调用搜索接口
  75.     httpget(trueurl, 'utf-8');
  76.     //将接口返回内容进行正则过滤后,回传给getImgUrl方法
  77.     regpick('getImgUrl', _GET.HTML, '/largeTnImageUrl":"(?<img>[^"]*?)"/is');
  78.     sleep(5000);
  79. }
  1. #language c
  2. /*
  3. 原理为先调用百度搜索接口,获取图片地址
  4. 根据图片地址再调用百度识图接口,获取同样一张图尺寸最大的一张高清图
  5. */
  6. //定义搜索关键字
  7. String    keyword = '高圆圆';
  8. //默认保存图片路径
  9. string    savepath = 'baiduImage/';
  10. //最大获取张数
  11. int    maxnum = 200;
  12. //百度图片搜索接口
  13. string    url = 'http://pic.baidu.com/i?tn=resultjson_com&sf=2&fmq=&istype=2&word=[[key]]&f=3&oe=utf-8&rn=60&pn=[[page]]';
  14. //百度识图签名接口
  15. string  stuindex = 'http://stu.baidu.com/i?objurl=[[url]]&filename=&rt=0&rn=10&ftn=searchstu&ct=1&stt=0&tn=shituresult';
  16. //百度识图图片接口
  17. string  stuurl = 'http://stu.baidu.com/i?dispView=imgView&sort=size&ct=3&querysign=[[query]]&objURL=[[url]]&bdTag=1&tn=shitujson&rn=60&pn=0';
  18.  
  19. //初始函数,设置refer地址,UA,cookie
  20. int initGet(){
  21.     _GET.clear;
  22.     _GET.referer = 'http://pic.baidu.com/';
  23.     _GET.useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64)';
  24.     _GET.cookie    = 'BAIDUID=B8F06EA0EBC15B615BD41688D47'+inttostr(rand(10, 99999))+':FG=1';
  25. }
  26. //根据图片地址保存图片
  27. int getImgUrl(TRegexp r,string m){
  28.     //根据关键字和MD5命名图片
  29.     String picfile = keyword+'_'+md5(r['img'], 16)+'.jpg';
  30.     //初始化
  31.     initGet();
  32.     //根据传入的图片地址,替换识图签名中的变量
  33.     newurl=replace(stuindex, '[[url]]', urlencode(r['img']));
  34.     //清空get对象
  35.     _GET.clear;
  36.     //调用识图签名接口
  37.     httpget(newurl);
  38.     //通过正则过滤GET对象中302地址的querysign参数
  39.     sign= Match(_GET.URL, 'querysign=(*)&');
  40.     //将地址替换识图图片接口中的url变量
  41.     picurl = replace(stuurl, '[[url]]',urlencode(r['img']));
  42.     //将签名替换识图接口中的query变量
  43.     picurl = replace(picurl, '[[query]]',sign);
  44.     //清空get对象
  45.     _GET.clear;
  46.     //用utf-8格式调用识图接口
  47.     httpget(picurl,'utf-8');
  48.     //将GET对象返回的HTML源码进行正则过滤
  49.     detailpic=Match(_GET.HTML,'"objURLEnc":"(*)"');
  50.     //获取图片地址,保存到定义的路径
  51.     httpget(detailpic, '', savepath+picfile);
  52.     //输出保存的图片地址用作进程输出
  53.     echo(detailpic);
  54.     //停止一秒
  55.     sleep(1000);
  56. }
  57.  
  58. {
  59. //main
  60.     //保存地址为当前路径+初始定义路径
  61.     savepath = _path()+savepath;
  62.     //检查是否为文件夹
  63.     isdir(savepath, true);
  64.     //将定义的关键词进行url转码替换百度搜索接口中的变量key
  65.     url = replace(url, '[[key]]', urlencode(keyword, true));
  66.     //设置每页数量                
  67.     persize = 60;
  68.     //用最大数量除每页数量向上取整,获得当前第几页
  69.     pages   = ceil(maxnum / persize);
  70.     //进行循环调取
  71.     for(int index=1;index<=pages;index++){
  72.         //替换page参数
  73.         trueurl = replace(url, '[[page]]', inttostr((index-1) * persize));
  74.         //初始化
  75.         initGet;
  76.         //调用搜索接口
  77.         httpget(trueurl, 'utf-8');
  78.         //将接口返回内容进行正则过滤后,回传给getImgUrl方法
  79.         regpick('getImgUrl', _GET.HTML, '/largeTnImageUrl":"(?<img>[^"]*?)"/is');
  80.         sleep(5000);
  81.     }
  82. }
  1. #language basic
  2. '原理为先调用百度搜索接口,获取图片地址
  3. '根据图片地址再调用百度识图接口,获取同样一张图尺寸最大的一张高清图
  4. '定义搜索关键字
  5. Dim keyword = "高圆圆"
  6. '默认保存图片路径
  7. Dim savepath = "baiduImage/"
  8. '最大获取张数
  9. Dim maxnum = 200
  10. '百度图片搜索接口
  11. Dim url = "http://pic.baidu.com/i?tn=resultjson_com&sf=2&fmq=&istype=2&word=[[key]]&f=3&oe=utf-8&rn=60&pn=[[page]]"
  12. '百度识图签名接口
  13. Dim stuindex = "http://stu.baidu.com/i?objurl=[[url]]&filename=&rt=0&rn=10&ftn=searchstu&ct=1&stt=0&tn=shituresult"
  14. '百度识图图片接口
  15. Dim stuurl = "http://stu.baidu.com/i?dispView=imgView&sort=size&ct=3&querysign=[[query]]&objURL=[[url]]&bdTag=1&tn=shitujson&rn=60&pn=0"
  16.  
  17. '初始函数,设置refer地址,UA,cookie
  18. function initGet
  19.      _GET.clear
  20.      _GET.referer = "http://pic.baidu.com/"
  21.      _GET.useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64)"
  22.      _GET.cookie    = "BAIDUID=B8F06EA0EBC15B615BD41688D47"+inttostr(rand(10, 99999))+":FG=1"
  23. end function
  24. '根据图片地址保存图片
  25. function getImgUrl(r, m)
  26.     '根据关键字和MD5命名图片
  27.     Dim picfile = keyword+"_"+md5(r["img"], 16)+".jpg"
  28.     '初始化
  29.     initGet()
  30.     '根据传入的图片地址,替换识图签名中的变量
  31.     newurl = replace(stuindex, "[[url]]", urlencode(r["img"]))
  32.     '清空get对象
  33.     _GET.clear
  34.     '调用识图签名接口
  35.     httpget(newurl)
  36.     '通过正则过滤GET对象中302地址的querysign参数
  37.     sign = Match(_GET.URL, "querysign=(*)&")
  38.     '将地址替换识图图片接口中的url变量
  39.     picurl = replace(stuurl, "[[url]]",urlencode(r["img"]))
  40.     '将签名替换识图接口中的query变量
  41.     picurl = replace(picurl, "[[query]]",sign)
  42.     '清空get对象
  43.     _GET.clear
  44.     '用utf-8格式调用识图接口
  45.     httpget(picurl,"utf-8")
  46.     '将GET对象返回的HTML源码进行正则过滤
  47.     detailpic=Match(_GET.HTML, "objURLEnc"":""(*)""")
  48.     '获取图片地址,保存到定义的路径
  49.     httpget(detailpic, "", savepath+picfile)
  50.     '输出保存的图片地址用作进程输出
  51.     echo(detailpic)
  52.     '停止一秒
  53.     sleep(1000)
  54. end function
  55.  
  56. '保存地址为当前路径+初始定义路径
  57. savepath = savepath
  58. '将定义的关键词进行url转码替换百度搜索接口中的变量key
  59. url = replace(url, "[[key]]", urlencode(keyword, true))
  60. '设置每页数量                
  61. persize = 60
  62. '用最大数量除每页数量向上取整,获得当前第几页
  63. pages   = ceil(maxnum / persize)
  64. '进行循环调取
  65. for index = 1 to pages
  66.     '替换page参数
  67.     trueurl = replace(url, "[[page]]", inttostr((index-1) * persize))
  68.     '初始化
  69.     initGet()
  70.     '调用搜索接口
  71.     httpget(trueurl, "utf-8")
  72.     '将接口返回内容进行正则过滤后,回传给getImgUrl方法
  73.     regpick("getImgUrl", _GET.HTML, "/largeTnImageUrl"":""(?<img>[^""]*?)""/is")
  74.     sleep(5000)
  75. next

第16课 - 语音阅读(Use TTS Engine)


Pascal Js C Basic

[评论 - Comment] [下载例子 - Down] | [复制 - Copy]

  1. #language pascal
  2. begin
  3.     //创建ole对象 , sapi tts 语音
  4.     voiceOle := createoleobject('sapi.spvoice');
  5.     //取所有安装过的voice
  6.     voices := voiceOle.GetVoices();
  7.     for i := 0 to voices.count-1 do
  8.         echo(voices.item[i].id);
  9.     //语速 -10 到 10
  10.     voiceOle.rate   :=4;
  11.     //声音大小 0 到 100
  12.     voiceOle.volume := 100;
  13.     //开始语音
  14.     voiceOle.speak('1 2 3 speak chinese: 世界,你好!');
  15. end.
  1. #language js
  2. //创建ole对象 , sapi tts 语音
  3. var voiceOle = createoleobject("sapi.spvoice"),
  4.     //取所有安装过的voice
  5.     voices = voiceOle.GetVoices();
  6. for(var i = 0; i < voices.count; i++){
  7.     echo(voices.item[i].id);
  8. }
  9. //语速 -10 到 10
  10. voiceOle.rate   = 4;
  11. //声音大小 0 到 100
  12. voiceOle.volume = 100;
  13. //开始语音
  14. voiceOle.speak('1 2 3 speak chinese: 世界,你好!');
  1. #language c
  2. {
  3.     //创建ole对象 , sapi tts 语音
  4.     voiceOle = createoleobject("sapi.spvoice");
  5.     //取所有安装过的voice
  6.     voices = voiceOle.GetVoices();
  7.     for(int i = 0; i < voices.count; i++){
  8.         echo(voices.item[i].id);
  9.     }
  10.     //语速 -10 到 10
  11.     voiceOle.rate   = 4;
  12.     //声音大小 0 到 100
  13.     voiceOle.volume = 100;
  14.     //开始语音
  15.     voiceOle.speak('1 2 3 speak chinese: 世界,你好!');
  16. }
  1. #language basic
  2. '创建ole对象 , sapi tts 语音
  3. Dim voiceOle = createoleobject("sapi.spvoice")
  4. '取所有安装过的voice
  5. Dim voices = voiceOle.GetVoices()
  6.  
  7. for i = 0 to voices.count
  8.     echo(voices.item[i].id)
  9. next
  10.  
  11. '语速 -10 到 10
  12. voiceOle.rate   = 4
  13. '声音大小 0 到 100
  14. voiceOle.volume = 100
  15. '开始语音
  16. voiceOle.speak("1 2 3 speak chinese 世界,你好!")