在我的应用中,当我使用urlfetch.fetch函数来获取指定的url时,我发现对于一些特殊的html代码,我得到的内容是空的。
例如,实际html源代码中的url:http://www.club.cn.sodexo.com/node/5071,代码包括:
<div class="content">
<div style="width: 219px; height: 262px;" id="gmap-auto3map-gmap0" class="gmap-control gmap-gmap gmap gmap-map gmap-auto3map-gmap">Javascript is required to view this map.</div>
<script type="text/javascript">
/* <![CDATA[ */
jQuery.extend(true, Drupal, { settings: { "gmap": { "auto3map":{ "width": "219px", "height": "262px", "zoom": 16, "maxzoom": "17","controltype": "Large", "align": "None", "maptype": "Map", "mtc":"none", "baselayers": { "Map": 1, "Satellite": 1, "Hybrid": 1 },"styles": { "line_default": [ "0000ff", "5", "45", "", "" ],"poly_default": [ "000000", "3", "25", "ff0000", "45" ] },"line_colors": [ "#00cc00", "#ff0000", "#0000ff" ], "behavior":{ "autozoom": true }, "markermode": "0", "id": "auto3map", "latitude":"31.239132", "longitude": "121.483506", "markers": [ { "latitude":"31.239132", "longitude": "121.483506", "markername": "small red","offset": 0, "opts": { "title": "克莉丝汀食品(宁波路店)" }, "text": "\x3cdiv class=\"gmap-popup\"\x3e\x3c/div\x3e" } ] } } } });
/* ]]> */
</script>
</div> 但是从我通过url fetch得到的:结果是:
<div class="content">
<div style="width: 219px; height: 262px;" id="gmap-auto3map-gmap0" class="gmap-control gmap-gmap gmap gmap-map gmap-auto3map-gmap">Javascript is required view this map.</div>
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>/* <![CDATA[ */和/* ]]> */之间的所有javascript代码都被遗漏了,这是如此紧密相连。有人知道问题出在哪里吗?是否有可能解决此问题?
发布于 2011-03-31 11:49:34
也许服务器会根据用户代理插入不同的javascript (即Firefox与Internet Explorer的不同代码),而对于urlfetch的用户代理,服务器会感到困惑,根本不会插入任何javascript。
https://stackoverflow.com/questions/2310134
复制相似问题