首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >节点js需要html body中的数据。

节点js需要html body中的数据。
EN

Stack Overflow用户
提问于 2018-06-04 02:17:57
回答 1查看 107关注 0票数 0

我有一个网址,我需要从html检索一些数据,以进一步工作。

代码语言:javascript
复制
var request = require('request');
request('http://10.9.1.252:8111/goip/en/dosend.php?USERNAME=root&PASSWORD=root&smsprovider=2&smsnum=0036301234567&method=2&Memo=Test', function (error, response, body) {
  console.log('error:', error); 
  console.log('statusCode:', response && response.statusCode); 
  console.log('body:', body); 
});

使用下面的代码,我得到了以下输出:

代码语言:javascript
复制
error: null
statusCode: 200
body: <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<title>Sending Messge</title>
</head>
<body>


<br>total will send: 1 <br><script language='javascript'>window.location = 'resend.php?messageid=85&USERNAME=root&PASSWORD=root'</script>

如何从html中检索messageid?有人能帮我一下吗?

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 02:33:01

要做到这一点,最快、最糟糕的方法就是使用regular expression

代码语言:javascript
复制
const regex = /messageid=(\d+)/g
const messageId = regex.exec(body)[1]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50669571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档