显然,我对 Javascript 的了解比我愿意承认的要新一些。我正在尝试使用 Node.js 拉网页并将内容保存为变量,因此我可以按照自己的意愿对其进行解析。
在 Python 中,我会这样做:
from bs4 import BeautifulSoup # for parsing
import urllib
text = urllib.urlopen("http://www.myawesomepage.com/").read()
parse_my_awesome_html(text)
我将如何在 Node 中执行此操作?我已经做到了:
var request = require("request");
request("http://www.myawesomepage.com/", function (error, response, body) {
/*
Something here that lets me access the text
outside of the closure
This doesn't work:
this.text = body;
*/
})