3

So, I have a Bottle page within PythonAnywhere that is displaying a list of items in my SQLite database. In each of those tappable items, I want to give the other page relevant information from the database based on the name of the list item that was clicked.

So in this case, I want to grab the value of this element and use the variable in my SQLite query via Python.

<ons-list-item id="itembtn" name="itembtn" value="{{ record [0] }}" tappable>

However, it is to my knowledge that the value of an HTML element isn't possible to retrieve. I am wondering if anyone knows of a way to grab this dynamic value with Python.

<!-- Parts showing from database -->
        <template id="caseFanResult.html">
            <% result = c.execute("SELECT * FROM caseFanPart")%>
                <ons-page id="caseFanResult">
                    <ons-toolbar>
                        <div class="left">
                            <ons-back-button>Back</ons-back-button>
                        </div>
                        <div class="center">Case Fan Parts</div>
                    </ons-toolbar>
                    <ons-list modifier="material">
                        %for record in result:
                        <ons-list-item id="itembtn" name="itembtn" value="{{ record [0] }}" tappable>
                            <div class="center">
                                <span class="list-item__title">{{ record[1] }}</span>
                                <span class="list-item__subtitle">{{ record[2] }}</span>
                            </div>
                        </ons-list-item>
                        %end
                    </ons-list>
                </ons-page>
        </template>

        <!-- Parts detailed spec sheet -->
        <template id="itemResult.html">
            <% 
            id = request.form.get("itembtn","")
            itemResult = c.execute("SELECT * FROM caseFanPart WHERE caseFanID = ?", (id,))
            %>

                <ons-page id="itemResult">
                    <ons-toolbar>
                        <div class="left">
                            <ons-back-button>Back</ons-back-button>
                        </div>
                        <div class="center">Spec Sheet</div>
                    </ons-toolbar>
                    <ons-list modifier="material">
                        %for item in itemResult:
                        <ons-list-header>{{ item[1] }}</ons-list-header>
                        <ons-list-item>Price: {{ item[2] }}</ons-list-item>
                        <ons-list-item>Rating: {{ item[3] }}</ons-list-item>
                        <ons-list-item>Color: {{ item[4] }}</ons-list-item>
                        <ons-list-item>Size: {{ item[5] }}</ons-list-item>
                        <ons-list-item>RPM: {{ item[6] }}</ons-list-item>
                        <ons-list-item>Airflow: {{ item[7] }}</ons-list-item>
                        <ons-list-item>Noise Level:{{ item[8] }}</ons-list-item>
                        %end
                    </ons-list>
                </ons-page>
        </template>

1 Answer 1

2

This is what you have to do to extract a value from an HTML element

import bs4 as bs

word = '<ons-list-item id="itembtn" name="itembtn" value="{{ record [0] }}" tappable>'

soup = bs.BeautifulSoup(word,'lxml')

supa = soup.find('ons-list-item',attrs={'id' : 'itembtn'})

value = supa.get('value')
#print(value)

#to find all values 
valuelist = []
supa = soup.find_all('ons-list-item',attrs={'id' : 'itembtn'})
for val in supa: 
    value = val.get('value')
    valuelist.append(value)
print(valuelist)
Sign up to request clarification or add additional context in comments.

1 Comment

this seems like an amazing idea, but looping through all of the values doesn't seem to work. The goal is to grab the values of each record and use that as the value for the sqlite query. So when you click one list item, it will transfer it's corresponding value number to the next page to display relevant information. Any ideas on this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.