79668740

Date: 2025-06-17 08:55:07
Score: 7.5 🚩
Natty:
Report link

I currently have a similar problem with my Python script.

I have a "script.py" file in which I parse the HTML code of a webpage and look for different elements, among which this one:

<div class="stock available" title="Disponibilité">
    <span>
       En stock
    </span>
</div>

Here is the part of my code looking for this element in "script.py":

import requests
from bs4 import BeautifulSoup
headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.57'
        }
page = requests.get("target_website.com", headers = headers, verify = False)
html = BeautifulSoup(page.text, "html.parser")

element_dispo = html.find('div', {'title':'Disponibilité'})
element_dispo = element_dispo.get('class') if element_dispo else []
dispo = 'Dispo' if 'available' in element_dispo else 'Non dispo'

When running the script by itself, everything works as expected, but if I try to execute the "script.py" file from the "main_script.py" file, with the code below, then the wanted element is not found.

with open("script.py") as file:
    exec(file.read())

Does anyone have any idea of what's happening?

Reasons:
  • RegEx Blacklisted phrase (3): Does anyone have any idea
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): have a similar problem
  • Ends in question mark (2):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: BMML