# Help me run this python script

**URL:** <https://discourse.nodered.org/t/help-me-run-this-python-script/73024>\
**Category:** General\
**Created:** [1 January 2023 16:57 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024 "2023-01-01T16:57:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [1 January 2023 16:57 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/1 "2023-01-01T16:57:41Z")

</div>

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

```auto
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}")

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 January 2023 18:22 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/2 "2023-01-01T18:22:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [1 January 2023 18:27 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/3 "2023-01-01T18:27:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fb5b008ac89d6b5258744a2bd8e23d486a76ad89.png)

---

<div class="post-metadata">

**Author:** ![ChankyTheConqueror](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chankytheconqueror/32/52296_2.png) [@ChankyTheConqueror](https://discourse.nodered.org/u/ChankyTheConqueror)\
**Post date:** [1 January 2023 19:14 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/4 "2023-01-01T19:14:40Z")

</div>

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

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

```auto
[
    {
        "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

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [1 January 2023 19:39 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/5 "2023-01-01T19:39:37Z")

</div>

which python library should I install?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad0a18fd188cb7e8e954b1e3960366a60bf88519.png)  
also im using nodered inside home assistant soo i have no idea where can i find the library folder

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 January 2023 20:23 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/6 "2023-01-01T20:23:40Z")

</div>

> [@boo](#):
>
> which python library should I install?

You don't need any of those

> [@boo](#):
>
> im using nodered inside home assistant

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.

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [1 January 2023 20:36 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/7 "2023-01-01T20:36:36Z")

</div>

> [@boo](#):
>
> i use nodered in home assistant.

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 March 2023 20:36 UTC](https://discourse.nodered.org/t/help-me-run-this-python-script/73024/8 "2023-03-02T20:36:38Z")

</div>

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