main.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package main
  2. import (
  3. "container/list"
  4. "embed"
  5. be "spider_creator/backend"
  6. bdb "spider_creator/backend/db"
  7. "spider_creator/backend/script"
  8. bvm "spider_creator/backend/vm"
  9. bws "spider_creator/backend/webservice"
  10. "github.com/wailsapp/wails/v2"
  11. "github.com/wailsapp/wails/v2/pkg/options"
  12. "github.com/wailsapp/wails/v2/pkg/options/assetserver"
  13. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  14. )
  15. var (
  16. //go:embed all:frontend/dist
  17. assets embed.FS
  18. app *App
  19. db *bdb.SpiderDb
  20. exitCh chan bool
  21. baseDir, attachesDir string = ".", ""
  22. currentSpiderConfig *be.SpiderConfig = new(be.SpiderConfig)
  23. currentResults = list.New() //b.ResultItems = make(b.ResultItems, 0)
  24. vm *bvm.VM
  25. glvm *script.GLVm
  26. ws *bws.WebService
  27. browserLoadResourceTimeout int64 = 5
  28. //重点网站和正式环境
  29. //isOnly4MainSite = "false"
  30. browserDisableLoadResources = "ws://;wss://;.tof;.woff;.ico;.mp4;.zip;.rar;.exe;"
  31. //serverAddress = "http://visualizeld.spdata.jianyu360.com/%s" //正式环境
  32. //serverAddress = "http://visualizepx.spdata.jianyu360.com/%s" //培训环境
  33. serverAddress = "https://jsspider.jydev.jianyu360.com:19092/%s" //含证书版本
  34. //serverAddress = "https://127.0.0.1:8091/%s" //测试环境
  35. //验证码服务
  36. serverCodeTimeOut int64 = 15
  37. serverCodeAddress = "http://pycaptcha.spdata.jianyu360.com/v1/images/discern?pic_type="
  38. serverCodeFreeAddressOcr = "http://pycaptcha.spdata.jianyu360.com/v1/images/verify"
  39. serverCodeFreeAddressArithmetic = "http://pycaptcha.spdata.jianyu360.com/v1/images/arithmetic"
  40. serverCodeUsername = "jianyu001"
  41. serverCodePassword = "123qwe!A"
  42. )
  43. //build
  44. // wails build -ldflags="-X 'main.isOnly4MainSite=false'" -o="剑鱼可视化爬虫开发工具_正式.exe"
  45. func init() {
  46. //be.LoadConfig("config.yaml")
  47. //从配置文件外,编译时设定浏览器排除加载资源。比配置文件优先级低
  48. if browserDisableLoadResources != "" {
  49. be.Cfg.DisableLoadResource = browserDisableLoadResources
  50. }
  51. if browserLoadResourceTimeout > 0 {
  52. be.Cfg.BrowserLoadResourceTimeout = browserLoadResourceTimeout
  53. }
  54. //验证码
  55. if serverCodeTimeOut > 0 {
  56. be.Cfg.ServerCodeTimeOut = serverCodeTimeOut
  57. }
  58. if serverCodeAddress != "" {
  59. be.Cfg.ServerCodeAddress = serverCodeAddress
  60. }
  61. if serverCodeFreeAddressOcr != "" {
  62. be.Cfg.ServerCodeFreeAddressOcr = serverCodeFreeAddressOcr
  63. }
  64. if serverCodeFreeAddressArithmetic != "" {
  65. be.Cfg.ServerCodeFreeAddressArithmetic = serverCodeFreeAddressArithmetic
  66. }
  67. if serverCodeUsername != "" {
  68. be.Cfg.ServerCodeUsername = serverCodeUsername
  69. }
  70. if serverCodePassword != "" {
  71. be.Cfg.ServerCodePassword = serverCodePassword
  72. }
  73. ////客户端版本
  74. //be.Cfg.IsOnly4MainSite = isOnly4MainSite == "true"
  75. //if be.Cfg.IsOnly4MainSite {
  76. // serverAddress = "http://visualize.spdata.jianyu360.com/%s" //重点网站
  77. //}
  78. qu.Debug("重点网站:", be.Cfg.IsOnly4MainSite, serverAddress)
  79. }
  80. func main() {
  81. go updateData() //数据保存
  82. // Create an instance of the app structure
  83. app = NewApp()
  84. // Create application with options
  85. err := wails.Run(&options.App{
  86. Title: "剑鱼-爬虫开发平台 v1.0",
  87. Width: 1350,
  88. Height: 668,
  89. AssetServer: &assetserver.Options{
  90. Assets: assets,
  91. },
  92. BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
  93. OnStartup: app.startup,
  94. OnShutdown: app.destory,
  95. Bind: []interface{}{
  96. app,
  97. },
  98. })
  99. if err != nil {
  100. println("Error:", err.Error())
  101. }
  102. }