I always try to make useful program to learn a Programming Language. Now I am trying to learn Python. I will try to post my practice code here. Today I will show you how to grab all links of web page using Python's "BeautifulSoup" module.
- import urllib,BeautifulSoup
- def get_links(url):
- page = urllib.urlopen(url)
- soup = BeautifulSoup.BeautifulSoup(page.read())
- aTag = soup.findAll("a")
- link = []
- for a in aTag:
- if a.has_key("href"):
- link.append(a['href'])
- return link
- print get_links("http://localhost/PRACTIECE/a2/")
Enjoy!!!
BeautifulSoup is not pre-installed. You have to install it manually.
ReplyDelete