我嗅了一下HTTP包,我知道响应是这样的:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Thu, 17 Sep 2015 18:32:14 GMT
Vary: Accept-Encoding
Content-Length: 175
Connection: keep-alive
http://www.example.com/abc.mp3
请注意,Content-Type
被错误地返回为text/xml
。实际的响应主体只是一个URL。我已尝试casper.getPageContent()
和require('utils').dump(this.page.content);
以及其他一些方法尝试获取正确的响应正文(URL),但都失败了。
casper.getPageContent()
的结果是:
<html xmlns="http://www.w3.org/1999/xhtml"><body><parsererror style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 1 at column 1: Start tag expected.</div><h3>Below is a rendering of the page up to the first error.</h3></parsererror></body></html>
我的问题是,如何在HTTP响应正文中获取URL?感谢。
顺便说一下,你可以使用fiddler的AutoResponder来伪造这个响应,以便在需要时进行测试。