Help me run this python script

Hi can someone help me run this python script in nodeRed and print the message.

import cfscrape
import requests
from bs4 import BeautifulSoup

# Use cfscrape to bypass Cloudflare protection
scraper = cfscrape.create_scraper()

# Send a GET request to the website
response = scraper.get("https://robu.in/product/spx3819m5-l-3-3-tr-500ma-low-noise-ldo-voltage-regulator-5-pin-sot-23/")

# Parse the HTML content
soup = BeautifulSoup(response.content, "html.parser")

# Find the element containing the availability information
availability_element = soup.find("p", class_="stock in-stock")
availability_element1 = soup.find("p", class_="stock out-of-stock")

# Extract the availability information
if availability_element:
    availability = availability_element.text
    print(f"Availability: {availability}")
elif availability_element1:
    availability1 = availability_element1.text
    print(f"Availability: {availability1}")


Does it run in a command terminal? If so you should be able to call it from a exec node. Use the full path to the script file.
Put debug nodes showing complete message on all outputs of the exec node when you test it.

Where do you want to print it?

1 Like

thanks and yes its executable from cmd in windows and it prints the data of availability. i want it to print as payload soo i can make some automation in nodered. i use nodered in home assistant.
error 127. I dont have python installed in nodered

Hi,
just like Colin said try with the full paths.

It works on my node-red enviroment, try the code below

[
    {
        "id": "aee3d9b5594bfbc6",
        "type": "exec",
        "z": "af515919.f8e918",
        "command": "/usr/bin/python3",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "10",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 680,
        "y": 680,
        "wires": [
            [
                "346ff9595afb8a41"
            ],
            [
                "0b50f85c567bbe4f"
            ],
            [
                "5f9c81d880fe8f1a"
            ]
        ]
    },
    {
        "id": "c3c7e447d402db74",
        "type": "inject",
        "z": "af515919.f8e918",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "~/temp/test.py",
        "payloadType": "str",
        "x": 450,
        "y": 680,
        "wires": [
            [
                "aee3d9b5594bfbc6"
            ]
        ]
    },
    {
        "id": "346ff9595afb8a41",
        "type": "debug",
        "z": "af515919.f8e918",
        "name": "out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 640,
        "wires": []
    },
    {
        "id": "0b50f85c567bbe4f",
        "type": "debug",
        "z": "af515919.f8e918",
        "name": "error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 700,
        "wires": []
    },
    {
        "id": "5f9c81d880fe8f1a",
        "type": "debug",
        "z": "af515919.f8e918",
        "name": "result",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 760,
        "wires": []
    }
]

best regards

1 Like

which python library should I install?


also im using nodered inside home assistant soo i have no idea where can i find the library folder

You don't need any of those

You should have mentioned that, it makes it all more complex You will probably have to ask in a Home Assistant forum, or drop HA and just use node-red. Few here use HA as it seems to add complexity with no obvious rewards.

@Colin I already mentioned, thanks. i will try to figure out with HA community and update here

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.