Reputation: 6938
<a class="cscore_link" name="&lpos=house:schedule:final" href="https://www.url.com-2019-20">
There are multiple classes of cscore_link
in the html
, but the value of name
attribute differs. I need to get the href value of all the cscore_link
class where the value of name
has a substring of final
Upvotes: 0
Views: 92
Reputation: 33384
If you have Beautiful soup 4.7.1 or above you can use following css selector to find name
contains final
.
print(soup.select(".cscore_link[name*='final']"))
Or You can check name ends with final
.
print(soup.select(".cscore_link[name$='final']"))
Upvotes: 1
Reputation: 82815
Use Regex.
Ex:
import re
from bs4 import BeautifulSoup
html = """<a class="cscore_link" name="&lpos=house:schedule:final" href="https://www.url.com-2019-20"></a>
<a class="cscore_link" name="&lpos=house:schedule" href="https://www.url.com-2019-20"></a>
"""
soup = BeautifulSoup(html, 'html.parser')
print(soup.find_all('a', {'class':'cscore_link', 'name': re.compile(r":final\b")}))
Output:
[<a class="cscore_link" href="https://www.url.com-2019-20" name="&lpos=house:schedule:final"></a>]
Upvotes: 1