2017-08-02 78 views
3

我想创建Azure Logic App,它会不断请求Internet上的特定网站并解析收到的HTML。解析Azure逻辑应用程序中的文本

我已经创建了逻辑应用程序并设置了时间间隔和HTTP请求操作。

我应该选择哪一个动作为简单的regex操作上的HTML代码中的下一步是什么?

我想到的是创造Azure Function这将完成这项工作,但我不知道是否有任何其他解决方案,更适合这样的任务。

我希望它尽可能简单。


编辑:

刚刚发现了一些很酷的功能。 Logic应用程序包含一些基本类型的基本表达式。

不幸的是它缺少任何regexstring.contains

现在,我将尝试使用Azure函数。

+1

Azure的功能将是我的建议。你也可以建立一个自定义连接器,但这可能会带来更多的开销。 –

回答

0

我已经成功地解决了我的使用Workflow Definition Language和积木通过Azure的提供问题。

Azure Function的想法并没有那么糟糕,完全适合于任何更复杂的情况,但正如我所提到的,我希望它尽可能简单,所以就是这样。

这就是我现在的流程。

为了完整起见,这里是JSON格式的流

{ 
    "$connections": { 
     "value": { 
      "wunderlist": { 
       "connectionId": "/subscriptions/.../providers/Microsoft.Web/connections/wunderlist", 
       "connectionName": "wunderlist", 
       "id": "/subscriptions/.../providers/Microsoft.Web/locations/northeurope/managedApis/wunderlist" 
      } 
     } 
    }, 
    "definition": { 
     "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", 
     "actions": { 
      "Condition": { 
       "actions": { 
        "Create_a_task": { 
         "inputs": { 
          "body": { 
           "completed": false, 
           "list_id": 000000000, 
           "starred": true, 
           "title": "@{variables('today date')}" 
          }, 
          "host": { 
           "connection": { 
            "name": "@parameters('$connections')['wunderlist']['connectionId']" 
           } 
          }, 
          "method": "post", 
          "path": "/tasks", 
          "retryPolicy": { 
           "type": "none" 
          } 
         }, 
         "limit": { 
          "timeout": "PT20S" 
         }, 
         "runAfter": {}, 
         "type": "ApiConnection" 
        }, 
        "Set_a_reminder": { 
         "inputs": { 
          "body": { 
           "date": "@{addHours(utcNow(), 3)}", 
           "list_id": 000000, 
           "task_id": "@body('Create_a_task')?.id" 
          }, 
          "host": { 
           "connection": { 
            "name": "@parameters('$connections')['wunderlist']['connectionId']" 
           } 
          }, 
          "method": "post", 
          "path": "/reminders", 
          "retryPolicy": { 
           "type": "none" 
          } 
         }, 
         "limit": { 
          "timeout": "PT20S" 
         }, 
         "runAfter": { 
          "Create_a_task": [ 
           "Succeeded" 
          ] 
         }, 
         "type": "ApiConnection" 
        } 
       }, 
       "expression": "@contains(body('HTTP'), variables('today date'))", 
       "runAfter": { 
        "Initialize_variable": [ 
         "Succeeded" 
        ] 
       }, 
       "type": "If" 
      }, 
      "HTTP": { 
       "inputs": { 
        "method": "GET", 
        "uri": "..." 
       }, 
       "runAfter": {}, 
       "type": "Http" 
      }, 
      "Initialize_variable": { 
       "inputs": { 
        "variables": [ 
         { 
          "name": "today date", 
          "type": "String", 
          "value": "@{utcNow('yyyy/MM/dd')}" 
         } 
        ] 
       }, 
       "runAfter": { 
        "HTTP": [ 
         "Succeeded" 
        ] 
       }, 
       "type": "InitializeVariable" 
      } 
     }, 
     "contentVersion": "1.0.0.0", 
     "outputs": {}, 
     "parameters": { 
      "$connections": { 
       "defaultValue": {}, 
       "type": "Object" 
      } 
     }, 
     "triggers": { 
      "Recurrence": { 
       "recurrence": { 
        "frequency": "Day", 
        "interval": 1, 
        "startTime": "2017-08-01T23:55:00Z", 
        "timeZone": "UTC" 
       }, 
       "type": "Recurrence" 
      } 
     } 
    } 
} 
0

你可能是在正确的轨道上。 Azure函数将是现在实现这种权利的最合适的方式。一个API应用程序是一个选项,但这是一个比你需要更重的平台。

0

创建沿着线的天青功能:

{

log.Info;( “C#HTTP触发功能处理的请求。”)

// Get request body 

dynamic data = await req.Content.ReadAsAsync<object>(); 



// Set name to query string or body data 

string input = data?.input.ToString(); 

var regexJson = data?.regexList; 

var regexes = regexJson.ToObject<List<RegexReplace>>(); 



foreach (var regex in regexes) 

{ 

    var re = Regex.Replace(regex.Regex, "\\\\","\\"); 

    var replace = Regex.Replace(regex.Replace, "\\\\","\\"); 

    input = Regex.Replace(input, "\\\"","\""); 

    input = Regex.Replace(input, re, replace); 

} 



input = Regex.Replace(input, "[\\r\\n]", ""); 



return data.regexList == null 

    ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body") 

    : req.CreateResponse(HttpStatusCode.OK, input, "application/json"); 

}

公共类REGEXREPLACE

{

public string Regex { get; set; } 

public string Replace { get; set; } 

}

相关问题