【问题标题】:Parsing html using jsdom and jquery on nodejs在nodejs上使用jsdom和jquery解析html
【发布时间】:2012-02-07 23:44:36
【问题描述】:
<td class="main1">
<br>
<img width="519" height="768" alt="2011 New Year styles, in better quality!" src="http://www.causewaymall.com/shop/images/J-1045.5.jpg">
<br>
<img width="500" height="752" alt="2011 New Year styles, in better quality!" src="http://www.causewaymall.com/shop/images/T-3378.jpg">
</td>

如何使用 nodejs 获取 url 图像的代码?前任 : 这是我的代码:

var jsdom = require('jsdom');
var url = 'http://www.causewaymall.com/shop/-i-163.html';
jsdom.env(url,
    [
        'http://code.jquery.com/jquery-1.5.min.js'
    ],
    function(errors, window) {
        console.log("Url Image : =>  " + window.$(".main1 img").attr("src"));
    });

请告诉我先生。

【问题讨论】:

  • 现在打印什么?

标签: jquery node.js jsdom


【解决方案1】:

如果你的 html 看起来像这样:

<table>
  <tr>
    <td class="main1">
      <br>
      <img width="519" height="768" alt="2011 New Year styles, in better quality!" src="http://hmm.jpg">
      <br>
      <img width="500" height="752" alt="2011 New Year styles, in better quality!" src="http://hmm2.jpg">
    </td>
  </tr>
</table>

您应该能够使用以下方法提取 img src:

window.$('.main1').find('img').attr('src');

【讨论】:

    猜你喜欢
    • 2016-09-11
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 2011-08-14
    相关资源
    最近更新 更多