Mule ESB:阅读 HTML
Mule ESB : Read HTML
我有一种情况,我必须解析网页的结果。在这种情况下,该网站不提供 API 来使用来检索此数据。我创建了一个调用该网站的流程,但声明:
消息:发送 HTTP 请求时出错。消息负载的类型为:NullPayload
任何帮助将不胜感激。
<http:request-config name="HTTP_Request_Configuration" host="http://www.resellerratings.com/" port="80" doc:name="HTTP Request Configuration" basePath="/"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<logger message="#[message]" level="INFO" doc:name="Logger"/>
</flow>
鉴于您的配置,它可能因主机属性而失败,因为它不应包含协议。试试这个:
<http:request-config name="HTTP_Request_Configuration" host="www.resellerratings.com" port="80" doc:name="HTTP Request Configuration" />
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<logger message="#[message]" level="INFO" doc:name="Logger"/>
</flow>
试试这个:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:request-config name="remote_HTTP_Request_Configuration" host="www.resellerratings.com" port="80" doc:name="REMOTE HTTP Request Configuration" />
<http:listener-config name="local_HTTP_Request_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow1">
<http:listener config-ref="local_HTTP_Request_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="remote_HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
转到:http://localhost:8081/testReseller
您获得 html 页面:
现在,为了从这个网站获取信息。我认为骡子不是一个选择。您需要一个可以让您操纵 html dom 的工具。
这与质量 Assurance/Test 自动化有关。当然,我们的 java 有很棒的工具:
我与您分享我的代码:
- Jsoup 示例:从 youtube 频道获取视频和图像的标题
在此示例中,我从 youtube 频道获取所有视频 div(特定 class),并获取内容和标签。
- HTMLUnit 示例:自动化 gogole 翻译器:
在这个例子中,我转到 google 网络翻译器,在左侧框中输入一些词,按下翻译器按钮并从右侧框中获取响应。全部带 java.
最后,您可以将其中一些工具用作 java 组件并使用 mule 来调用它:
<flow name="testFlowHtmlParser">
<http:listener config-ref="local_HTTP_Request_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<component doc:name="Java" class="com.mycompany.HtmlParserComponent"/>
</flow>
如果您需要有关 html 解析器的帮助,请联系我:
我有一种情况,我必须解析网页的结果。在这种情况下,该网站不提供 API 来使用来检索此数据。我创建了一个调用该网站的流程,但声明:
消息:发送 HTTP 请求时出错。消息负载的类型为:NullPayload
任何帮助将不胜感激。
<http:request-config name="HTTP_Request_Configuration" host="http://www.resellerratings.com/" port="80" doc:name="HTTP Request Configuration" basePath="/"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<logger message="#[message]" level="INFO" doc:name="Logger"/>
</flow>
鉴于您的配置,它可能因主机属性而失败,因为它不应包含协议。试试这个:
<http:request-config name="HTTP_Request_Configuration" host="www.resellerratings.com" port="80" doc:name="HTTP Request Configuration" />
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<logger message="#[message]" level="INFO" doc:name="Logger"/>
</flow>
试试这个:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:request-config name="remote_HTTP_Request_Configuration" host="www.resellerratings.com" port="80" doc:name="REMOTE HTTP Request Configuration" />
<http:listener-config name="local_HTTP_Request_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow1">
<http:listener config-ref="local_HTTP_Request_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="remote_HTTP_Request_Configuration" path="/store/best_buy" method="GET" doc:name="HTTP" sendBodyMode="NEVER"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
转到:http://localhost:8081/testReseller
您获得 html 页面:
现在,为了从这个网站获取信息。我认为骡子不是一个选择。您需要一个可以让您操纵 html dom 的工具。
这与质量 Assurance/Test 自动化有关。当然,我们的 java 有很棒的工具:
我与您分享我的代码:
- Jsoup 示例:从 youtube 频道获取视频和图像的标题
在此示例中,我从 youtube 频道获取所有视频 div(特定 class),并获取内容和标签。
- HTMLUnit 示例:自动化 gogole 翻译器:
在这个例子中,我转到 google 网络翻译器,在左侧框中输入一些词,按下翻译器按钮并从右侧框中获取响应。全部带 java.
最后,您可以将其中一些工具用作 java 组件并使用 mule 来调用它:
<flow name="testFlowHtmlParser">
<http:listener config-ref="local_HTTP_Request_Configuration" path="/testReseller" allowedMethods="GET" doc:name="HTTP"/>
<component doc:name="Java" class="com.mycompany.HtmlParserComponent"/>
</flow>
如果您需要有关 html 解析器的帮助,请联系我: