python - How can I find all the 'name' elements that begin with a specific string? -
i'm working on personal project @ moment , ran trouble.
i'm using beautiful soup scrape user replies off web page. i'd scrape number of downvotes , upvotes on post haven't been able so.
below html contains number of upvotes user's post. each user has different name
element id shown 171119643
have been confused how can scrape name
elements.
<strong id="cmt_o_cnt_171119643" name="cmt_o_cnt_171119643">756</strong>
i did notice each name starts same string: cmt_o_cnt_
. there way can scrape elements starting string using code below?
for url in soup.find_all('strong', name_=''):
a non-regex solution check if substring "cmt_o_cnt_"
in tag['name']
:
for tag in soup.find_all('strong'): if "cmt_o_cnt_" in tag['name']: print(tag['name']) # or stuff
Comments
Post a Comment