NodeRed爬取CSDN博主的名称

先上流图

 用POSTMAN GET请求armcsdn的博客_CSDN博客-Node-Red,Arduino,Nodemcu领域博主

得到如下数据,注意下划红线的部分是需要提取的数据。

NodeRed GET请求 使用节点实现,url填入

https://blog.csdn.net/armcsdn

  对请求后返回的数据,使用html节点提取相关数据。

官网关于html的说明

 

选取项主要是根据css选取器选择网页的元素。

w3school关于CSS选取器的说明

本例博主的名称信息存在于 class="user-profile-title"下,所以选取项是.user-profile-title,注意最前面的点不要忘记。

以下是各函数节点截图

 

 

最终调试输出

 

 

 http request节点的url 更换成“单片机菜鸟哥”的博客

https://blog.csdn.net/dpjcn1990?type=blog

 

 完整流图程序

[
    {
        "id": "09f49222e93c26a6",
        "type": "tab",
        "label": "流程 6",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6cd2b1acf646d806",
        "type": "inject",
        "z": "09f49222e93c26a6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 230,
        "y": 400,
        "wires": [
            [
                "13dca52d359f0dcf"
            ]
        ]
    },
    {
        "id": "13dca52d359f0dcf",
        "type": "http request",
        "z": "09f49222e93c26a6",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://blog.csdn.net/armcsdn?spm=1008.2221.3001.5343",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 400,
        "y": 400,
        "wires": [
            [
                "3aeca66e59c04962"
            ]
        ]
    },
    {
        "id": "9567beb168d69146",
        "type": "debug",
        "z": "09f49222e93c26a6",
        "name": "原始数据输出",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 400,
        "wires": []
    },
    {
        "id": "3aeca66e59c04962",
        "type": "html",
        "z": "09f49222e93c26a6",
        "name": "",
        "property": "payload",
        "outproperty": "payload",
        "tag": ".user-profile-title",
        "ret": "html",
        "as": "single",
        "x": 600,
        "y": 400,
        "wires": [
            [
                "9567beb168d69146",
                "43c9847f008662e3"
            ]
        ]
    },
    {
        "id": "43c9847f008662e3",
        "type": "function",
        "z": "09f49222e93c26a6",
        "name": "从数组中提取字符串",
        "func": "var len=msg.payload;\nmsg.payload=len[len.length-1];//提取数组中的字符串\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 660,
        "y": 460,
        "wires": [
            [
                "be0a617b958deb21",
                "ef9fdd440af2d8fc"
            ]
        ]
    },
    {
        "id": "be0a617b958deb21",
        "type": "debug",
        "z": "09f49222e93c26a6",
        "name": "提取数组元素",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 460,
        "wires": []
    },
    {
        "id": "2eafaa36e513fbba",
        "type": "comment",
        "z": "09f49222e93c26a6",
        "name": "https://www.jb51.net/article/99274.htm",
        "info": "",
        "x": 530,
        "y": 340,
        "wires": []
    },
    {
        "id": "f076dbfecb66b4ca",
        "type": "debug",
        "z": "09f49222e93c26a6",
        "name": "字符串拆分成数组",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 520,
        "wires": []
    },
    {
        "id": "ef9fdd440af2d8fc",
        "type": "function",
        "z": "09f49222e93c26a6",
        "name": "拆分字符串",
        "func": "var str=msg.payload;\nvar n=str.split(\"&\");//拆分字符串\n//遍历数组,去除字符串前的“#”\nfor(i=0;i<n.length;i++)\n  {\n      if(n[i].match('#'))\n      {\n       n[i]=n[i].substr(2,4)   \n      }\n      \n  }\nmsg.payload=n;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 630,
        "y": 520,
        "wires": [
            [
                "f076dbfecb66b4ca",
                "01e96df6367a4c4c"
            ]
        ]
    },
    {
        "id": "01e96df6367a4c4c",
        "type": "function",
        "z": "09f49222e93c26a6",
        "name": "把utf-16编码转汉字",
        "func": "var jstr=new Array();\nvar obj=new Array();\nvar hz_str=\"\";\nvar str_han=msg.payload;\nhz_str=str_han[0]//获取英文博客名,如果是中文,则直接赋空值\nfor(i=1;i<str_han.length;i++)\n{\n  jstr[i]= '{\"ustr\": \"'+'\\\\u'+ str_han[i] +'\"}' \n  obj[i] = JSON.parse(jstr[i]);\n  hz_str=hz_str+obj[i].ustr;\n}\nmsg.payload=hz_str//博客名称\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 580,
        "wires": [
            [
                "b330f5fb94932d7d"
            ]
        ]
    },
    {
        "id": "b330f5fb94932d7d",
        "type": "debug",
        "z": "09f49222e93c26a6",
        "name": "获取博客名称",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 580,
        "wires": []
    },
    {
        "id": "d0dbb6b2df7a93be",
        "type": "comment",
        "z": "09f49222e93c26a6",
        "name": "https://www.jb51.net/article/76609.htm",
        "info": "",
        "x": 710,
        "y": 640,
        "wires": []
    }
]

后继:

随着摸索,我发现上文方法太麻烦,还有无需编程的方法。可直接输出博客名称。

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

armcsdn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值