-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.py
More file actions
15 lines (12 loc) · 895 Bytes
/
Copy pathtest1.py
File metadata and controls
15 lines (12 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from bs4 import BeautifulSoup
txt = '''<a id="body_BusinessSearchResultSummaryList_repBusinessList_lnkBusinessProfile_1" class="sr-item-link" href="http://www.mocality.co.ke/b/natros-pharmacy/natrosoh/innercore/medical-services/_/_/0cfe6a11-7bee-41f8-8d2e-6a472557201f?skw=pharmacys&rcnt=10">Natros Pharmacy</a>
<a id="body_BusinessSearchResultSummaryList_repBusinessList_lnkBusinessProfile_2" class="sr-item-link
" href="http://www.mocality.co.ke/b/natros-pharmacy/natrosoh/innercore/medical-services/_/_/0cfe6a11-
7bee-41f8-8d2e-6a472557201f?skw=pharmacys&rcnt=10">Natros Pharmacy</a>'''
match = 'body_BusinessSearchResultSummaryList_repBusinessList_lnkBusinessProfile'
match1 = u'sr-item-link'
soup = BeautifulSoup(txt, "html.parser")
for a in soup.findAll('a'):
if a.has_attr('class') and a['class'] == match1:
print a['href'], a.contents
print a['class']