1

when i trying to run this code on web, its loading only. result is not showing, please help me in this.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>it's me</title>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
    <py-env>
        - pandas
        - requests
        - BeautifulSoup


    </py-env>
</head>
<body>
    <py-script>
        import pandas as pd
import requests
from bs4 import BeautifulSoup

from bs4 import SoupStrainer as strainer
urls = []
titles = []
cost = []


def transform(url, TrackingPrice):
    r = requests.get(str(url))
    only_item_cells = strainer("div", attrs={"class": "_30jeq3 _16Jk6d"})
    soup = BeautifulSoup(r.content, 'lxml', parse_only= only_item_cells)
    ajay = soup.text
    price = ajay.replace("₹", "").replace(",", "")
    print(price, TrackingPrice)

    return


df=pd.read_csv("C:/Users\\Sudip\\Downloads\\flip.csv")
for i in range(0,len(df["URL"])):
    transform(df["URL"][i], df["TrackingPrice"][i])

    </py-script>

</body>
</html>

output is 'loading runtime, runtime created,Initializing components...' please help me in this error

Sudip550
  • 11
  • 5

2 Answers2

1

A couple of other quick observations. First <py-env> is being deprecated in favor of <py-config> (See deprecation warning in console and the relevant section of the tutorial 1). Second, "requests" is not currently supported by PyScript (although that is one of the features that seems to be in the most demand). The current workaround is to use "pyfetch", a wrapper of JavaScript's "fetch". Cheers!

mdlatt
  • 124
  • 5
0

If you look at your console, you'll see it's complaining there's no wheel for BeautifulSoup.

The correct dependency is BeautifulSoup4, not BeautifulSoup.

However, you can't access the local disk via PyScript, so pd.read_csv(...) won't work like you imagine.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • so what can i do for this problem, please help – Sudip550 Oct 17 '22 at 13:04
  • please help sir – Sudip550 Oct 17 '22 at 13:14
  • I don't know what you want to do. You can't read a file off disk, but you could probably use an `` field to let the user select one and read it using whatever APIs pyscript provides. – AKX Oct 17 '22 at 13:45
  • Yes, along the lines of what AKX says, see the discussion in the comments [here](https://stackoverflow.com/q/73453166/8508004). And then see something along the lines of what that information and AKX's comment is suggesting using pyscript [here](https://github.com/amrrs/pyscript-upload-download-repl). You basically read your local csv file into pyscript's in-browser realm. Do what you want with it and then download the modified data out. Note that example is a sketch of the framework. It definitely covers reading in well. Running: https://amrrs.github.io/pyscript-upload-download-repl/ – Wayne Oct 17 '22 at 16:53
  • As I try to point out [here](https://stackoverflow.com/q/73453166/8508004), if the audience is just you, you may want to just use JupyterLite to do this via WASM/pyodide as the Jupyter interface makes working with Pandas nice. The idea is very similar in that you have to think of the web assembly running it as inside your browser and you put in and bring stuff out. Then you have a notebook you can run later again in your own JupyterLite resource. – Wayne Oct 17 '22 at 16:59