【问题标题】:scraping with nodejs coffeescript and cheerio用 nodejs coffeescript 和cheerio 抓取
【发布时间】:2015-05-21 13:19:32
【问题描述】:

我有很多 name 类的 div,我需要从每个 div 中提取文本和 url

使用BeautifulSoup我试过了:

for i in BeautifulSoup(page).find_all('div', {'class': 'name'}):
    print i.text
    print i.find('a').get('href')

我是 nodejs/coffeescript 的新手,所以很难理解它是如何以这种方式工作的

$('div.name').each (i, element) ->
    console.log i

没用

【问题讨论】:

  • 这是一个 python 还是 javascript 问题?

标签: javascript python node.js coffeescript web-scraping


【解决方案1】:

如果你使用cheerio,你应该可以做到这一点。

$ = cheerio.load('you html document goes here')
$('div.name').each (i, element) -> 
    console.log el

cheerio docs

【讨论】:

  • ReferenceError: el 未定义
  • 如何获取元素的'a.href'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多