Python Forum
Feed List items with Integer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feed List items with Integer
#10
(May-19-2021, 07:30 AM)euras Wrote: thank you snippsat for your help! But I don't get it how to place that in an actual call for element. How to write that syntax on the following example?
As don't now content of contents ,here is example from other Thread taken step further.
I use BS as it's easier to show than Selenium,CSS selector usage would be the same
So generate new selectors to take out first name,so a working example of similar task that you are trying to do.
from bs4 import BeautifulSoup

html = '''\
<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>'''

soup = BeautifulSoup(html, 'lxml')
contents= soup.select('tr')
for inda, content in enumerate(contents, 1):
    print(soup.select_one(f'tr:nth-child({inda}) > td:nth-child(1)').text)
Output:
Firstname Jill Eve
Reply


Messages In This Thread
Feed List items with Integer - by euras - May-17-2021, 04:57 PM
RE: Feed List items with Integer - by menator01 - May-17-2021, 05:21 PM
RE: Feed List items with Integer - by euras - May-18-2021, 09:22 AM
RE: Feed List items with Integer - by snippsat - May-18-2021, 09:37 AM
RE: Feed List items with Integer - by euras - May-18-2021, 10:18 AM
RE: Feed List items with Integer - by snippsat - May-18-2021, 11:22 AM
RE: Feed List items with Integer - by euras - May-18-2021, 02:17 PM
RE: Feed List items with Integer - by snippsat - May-18-2021, 02:48 PM
RE: Feed List items with Integer - by euras - May-19-2021, 07:30 AM
RE: Feed List items with Integer - by snippsat - May-19-2021, 07:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 76 Yesterday, 01:16 PM
Last Post: ann23fr
  Draw bounding boxes on live feed Jerome 0 228 Jan-20-2024, 10:50 PM
Last Post: Jerome
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,256 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Finding combinations of list of items (30 or so) LynnS 1 836 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,497 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 2,403 May-26-2022, 01:37 PM
Last Post: Mark17
  how to assign items from a list to a dictionary CompleteNewb 3 1,535 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  How to parse a live feed in Python? Daring_T 2 3,953 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  Reading list items without brackets and quotes jesse68 6 4,521 Jan-14-2022, 07:07 PM
Last Post: jesse68
Question How to gather specific second-level items from a list chatguy 2 1,516 Dec-17-2021, 05:05 PM
Last Post: chatguy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020