试试这个:
<?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 的工具。
这与质量保证/测试自动化有关。当然,我们的 java 也有很棒的工具:
我与你分享我的代码:
- Jsoup 示例:从 youtube 频道获取视频和图片的标题
https://github.com/jrichardsz/api-java-rest-service-youtube/blob/master/code/src/test/java/org/jrichardsz/youtubeapi/rest/test/TestJSoup.java
在此示例中,我从 youtube 频道获取所有视频 div(特定类),并获取内容和标签。
- HTMLUnit 示例:自动化 gogole 翻译器:
https://github.com/jrichardsz/appdesktop-super-translator/blob/master/code/src/main/java/com/rnasystems/projects/translator/core/impl/HtmlUnitGoogleUITranslator.java
在这个例子中,我去谷歌网络翻译,在左边的框中输入一些单词,按下翻译按钮并从右边的框中得到响应。全部用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 解析器的帮助,请联系我:
http://jrichardsz.weebly.com/