5 examples of 'beautifulsoup get href text' in Python

Every line of 'beautifulsoup get href text' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
29def _extract_url_links(html):
30 """extract url links
31
32 &gt;&gt;&gt; _extract_url_links('aa<a href="link1">link1</a>bb<a href="link2">link2</a>cc')
33 ['link1', 'link2']
34 """
35 soup = BeautifulSoup(html, "html.parser")
36 return soup.find_all('a')
34def parse_all_href(self, output):
35 global all_href_parsed
36 all_href_parsed = []
37 for tag in output.findAll('a', href=True):
38 all_href_parsed.append(tag['href'])
39 return all_href_parsed
31@property
32def text(self):
33 text = re.sub('&lt;[^&gt;]*&gt;', '', self.html)
34 text = htmlParser.unescape(text)
35 return text.strip()
18def get_text(self, page, index=0):
19 contents = self.find(page)
20 if contents is not None and len(contents) &gt; index:
21 return contents[0].text
22 return None
6def get_href(attrs):
7 """Retourne la valeur de l'href
8
9 &gt;&gt;&gt; get_href([('href', '/partners/'), ('target', '_blank')])
10 '/partners/'
11 &gt;&gt;&gt; get_href([('class', 'color2'), ('href', 'http://bookre.org/reader?file=677155')])
12 'http://bookre.org/reader?file=677155'
13 &gt;&gt;&gt; get_href([('href', 'javascript:void(0)'), ('onclick', 'return false')])
14 'javascript:void(0)'
15 """
16
17 for attr, value in attrs:
18 if attr == 'href':
19 return value
20 return None

Related snippets