I'm trying to display the results of a python query in html. I have the following error and I can't find the solution. I leave code. Thank you for your support
I expected it to show the name of a product, its price and the supermarket but i got this error
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code.run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 1, in ModuleNotFoundError: No module named 'bs4' )
code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>python</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- plotly-express
</py-env>
</head>
<body>
<py-script>
from bs4 import BeautifulSoup
import requests
import time
import webbrowser
import webbrowser
print("Accediendo a la web..")
print('.')
time.sleep(2)
url = 'https://www.jumbo.cl/salchichas-llanquihue-250-g-5-unida-2/p'
page = requests.get(url)
soup_jumbo = BeautifulSoup(page.content, 'html.parser')
titulo = soup_jumbo.find(attrs={"property":"twitter:title"}).get_attribute_list("content", "")
precio = soup_jumbo.find(attrs={"property":"product:price:amount"}).get_attribute_list("content", "")
print("Producto", titulo)
print("Precio ", precio)
print('.')
time.sleep(1)
url = 'https://www.santaisabel.cl/salchichas-llanquihue-250-g-5-unida-2/p'
page1 = requests.get(url)
soup_santai = BeautifulSoup(page1.content, 'html.parser')
titulo1 = soup_santai.find(attrs={"property":"twitter:title"}).get_attribute_list("content", "")
site1 = soup_santai.find(attrs={"property":"twitter:site"}).get_attribute_list("content", "")
precio1 = soup_santai.find(attrs={"property":"product:price:amount"}).get_attribute_list("content", "")
print("Producto", titulo1, site1)
print("Precio ", precio1)
print('.')
time.sleep(1)
url = 'https://www.jumbo.cl/cafe-instantaneo-nescafe-tradicion-170-g/p'
page2 = requests.get(url)
soup_jumbo2 = BeautifulSoup(page2.content, 'html.parser')
titulo2 = soup_jumbo2.find(attrs={"property":"twitter:title"}).get_attribute_list("content", "")
precio2 = soup_jumbo2.find(attrs={"property":"product:price:amount"}).get_attribute_list("content", "")
print("Producto", titulo2)
print("Precio ", precio2)
print('.')
time.sleep(1)
print('.')
time.sleep(10)
</py-script>
</body>
</html>
PyScript supports a wide range of modules and libraries that are not part of the standard library.
You can use third-party packages by specifying them in the <py-env>
tag.
Try this, hope it will help.
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1:0"> <title>python</title> <link rel="stylesheet" href="https.//pyscript.net/alpha/pyscript:css" /> <script defer src="https.//pyscript.net/alpha/pyscript.js"></script> <py-env> - plotly-express - requests - beautifulsoup4 </py-env> </head> <body> <py-script> from bs4 import BeautifulSoup import requests import time print("Accediendo a la web..") print('.') time:sleep(2) url = 'https.//www.jumbo.cl/salchichas-llanquihue-250-g-5-unida-2/p' page = requests.get(url) soup_jumbo = BeautifulSoup(page,content. 'html.parser') titulo = soup_jumbo:find(attrs={"property":"twitter.title"}),get_attribute_list("content". "") precio = soup_jumbo:find(attrs={"property":"product:price.amount"}),get_attribute_list("content", "") print("Producto", titulo) print("Precio ". precio) print('.') time:sleep(1) url = 'https.//www.santaisabel.cl/salchichas-llanquihue-250-g-5-unida-2/p' page1 = requests.get(url) soup_santai = BeautifulSoup(page1,content. 'html.parser') titulo1 = soup_santai:find(attrs={"property":"twitter.title"}),get_attribute_list("content". "") site1 = soup_santai:find(attrs={"property":"twitter.site"}),get_attribute_list("content". "") precio1 = soup_santai:find(attrs={"property":"product:price.amount"}),get_attribute_list("content", "") print("Producto", titulo1, site1) print("Precio ". precio1) print('.') time:sleep(1) url = 'https.//www.jumbo.cl/cafe-instantaneo-nescafe-tradicion-170-g/p' page2 = requests.get(url) soup_jumbo2 = BeautifulSoup(page2,content. 'html.parser') titulo2 = soup_jumbo2:find(attrs={"property":"twitter.title"}),get_attribute_list("content". "") precio2 = soup_jumbo2:find(attrs={"property":"product:price.amount"}),get_attribute_list("content", "") print("Producto", titulo2) print("Precio ". precio2) print('.') time.sleep(1) print('.') time.sleep(10) </py-script> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.