zoukankan      html  css  js  c++  java
  • “58信息定时发布器” 编写纪要

    1。数据库中随机抽取记录:

      try
        if AQry1.Active then AQry1.Close;
        AQry1.Open;
        //AQry.First;
        Randomize;
        AQry1.MoveBy(Random(AQry1.RecordCount - 1));
      finally
        Str2 := AQry1.FieldByName('title').AsString;
        Str1 := AQry1.FieldByName('content').AsString;
        AQry1.Close;
      end;

    2。执行JS脚本的函数:

    function ExecJS(WebBrowser:TWebBrowser; Code: string):Variant;
    var
      Document:IHTMLDocument2;
      Window:IHTMLWindow2;
    begin
      // execute javascript in webbrowser
      Document:=WebBrowser.Document as IHTMLDocument2;
      if not Assigned(Document) then Exit;
      Window:=Document.parentWindow;
      if not Assigned(Window) then Exit;
      try
        Result:=Window.execScript(Code,'JavaScript');
      except
        on E:Exception do raise Exception.Create('Javascript error '+E.Message+' in: '#13#10+Code);
      end;
    end;

    3。截取字符串的函数:

    function GetHref(StrSource, StrBegin, StrEnd: string): string;
    var
      HrefStart,HrefEnd:integer;
    begin
      HrefStart:=AnsiPos(strbegin,strsource)+length(strbegin);
      HrefEnd:=AnsiPos(strend,strsource);
      result:=copy(strsource,HrefStart,HrefEnd-HrefStart);
    end;

    4,。获取当前WebBrowser的URL:

    LoginWeb.LocationURL;

    5。添加记录到ListView中:

          With ListView1.Items.Add do
          begin
            Caption := '成功';
            ImageIndex := 0;
            SubItems.Add(UrlStr);
          end;

    6。操作DBGridEh:

    原来只要代开了数据库,设置相关属性,就可以自己获取数据库的中数据,和那个Delphi自带的DBGrid差不多!

    7。判断数据库中某项是否应存在:

      Str1 := trim(Edit1.Text);
      AQuery.SQL.Clear;
      AQuery.SQL.Add('select * from webUser where UserName=:str1');
      AQuery.Parameters.ParamByName('str1').Value := Str1;
      Aquery.Open;

      if AQuery.RecordCount = 0 then

      begin
        ShowMessage('用户名不能重复!');
      end;

    8。对网页中某个Element的class进行操作:

    if Uppercase(fDiv.all.item(i).ClassName) = 'EDITOR' then

    begin

    //执行某些操作!

    end;

    http://xtty.xoom.it/58/index.html

  • 相关阅读:
    laravel 控制器方法里存get值 和 blade 模板获得闪存值的方法
    获取对象中的值的方法
    python3 语法小结
    集合一些方法陷阱
    文件的读写操作
    字符编码
    数字,字符串,列表,元祖,字典,集合类型内置方法
    if判断,while循环,for循环
    交互,格式化输出,运算符,解压缩!
    python基础知识
  • 原文地址:https://www.cnblogs.com/spider518/p/2143236.html
Copyright © 2011-2022 走看看