我正在使用cheerio来抓取下一个HTML。
<div class="google-map-wrap " style="padding-bottom:50px;">
<div class="google-map"></div><style>.google-map{width: 100%; height: 420px;}
.google-map img {max-width:none !important;}</style><script>jQuery(document).ready(function(){jQuery(".google-map").gmap3({marker:{address: "Periferico Sur 2020"},map:{options:{zoom: 14,}}});});
我尝试了以下选项但它们没有用。
预期=&#34; Periferico Sur 2020&#34;
$('div.google-map-wrap div.google-map').text()
$('div.google-map-wrap div.google-map').html()
$('div.google-map-wrap div.google-map').css()
但不工作的结果应该是地址。
答案 0 :(得分:0)
如前所述,cheerio将无法做到。但是请求已经有了html,所以我们可以使用它来查找indexOf()的字符串。例如:
html的
<div class="google-map-wrap " style="padding-bottom:50px;">
<div class="google-map"></div><style>.google-map{width: 100%; height: 420px;}
.google-map img {max-width:none !important;}</style>
<script>jQuery(document).ready(function(){jQuery(".google-map").gmap3({marker:{address: "Periferico Sur 2020"},map:{options:{zoom: 14,}}});});
的.js
var readAddress = function(html){
var idx1 = html.indexOf('{marker:{address: "');
var idx2 = idx1 + '{marker:{address: "'.length;
var idx3 = html.indexOf('"', idx2);
address = html.substring(idx2, idx3);
}
request(url, (err, res, data) => {
readAddress(data);
});