#coding: Utf-8
Import Urllib2
From BS4Import BeautifulSoup
Response=urllib2.urlopen ("Http://www.163.com")
Htmldoc=response.read ()
Soup = BeautifulSoup (Htmldoc,' Html.parser ',from_encoding=' Utf-8 ')
Links =soup.find_all ("A")
Print‘Print all Links‘)
For linkIn Links:
Print link.name,link[' href ']
PrintLen (links)
Execution results
Print all Links
A http://www.163.com/#f =topnav
A http://m.163.com/newsapp/#f =topnav
A http://music.163.com/#f =topnav
A http://yuedu.163.com/#f =topnav
A http://note.youdao.com/#f =topnav
A HTTP://Y.163.COM/?FROM=WSDH
A http://open.163.com/#f =topnav
A Http://caipiao.163.com/mobile/client_cp.jsp#from=yingyong
A Http://cidian.youdao.com/?vendor=topnav
A http://mail.163.com/client/dl.html?from=mail46
A http://www.lofter.com/?act=qb163rk_20141031_01
A http://study.163.com/client/download.htm?from=163app&utm_source=163.com&utm_medium=web_app&utm_ Campaign=business
A http://www.163.com/
A http://reg.163.com/
A http://reg.163.com/RecoverPassword.shtml?f=www
A http://mail.163.com/client/dl.html?from=mail46
A http://reg.email.163.com/mailregAll/reg0.jsp?from=163navi®Page=163
A Http://reg.vip.163.com/register.m?from=topnav
A http://reg.163.com/Logout.jsp
A Http://rd.da.netease.com/redirect?t=I4iYc8&p=EA7B9E&target=http%3A%2F%2Fwww.kaola.com%2F
A http://www.kaola.com/outter/promote/myzq.html
A http://www.kaola.com/outter/promote/mrcz.html
A http://www.kaola.com/outter/promote/jjry.html
A http://www.kaola.com/outter/promote/jkms.html
A http://www.kaola.com/outter/promote/yybj.html
A http://www.kaola.com/outter/promote/hwzy.html
A http://rd.da.netease.com/redirect?t=W1rULs&p=pESsw1&proId=1024&target=http%3A%2F%2Fwww.kaola.com% 2factivity%2fdetail%2f5288.html%3ftag%3dbe3d8d027a530881037ef01d304eb505
A http://www.kaola.com/outter/promote/khd.html
A http://email.163.com/#from =163nav_icon
A http://email.163.com/#f =topnav
A http://vipmail.163.com/#f =topnav
A http://qiye.163.com/#f =topnav
A http://reg.email.163.com/mailregAll/reg0.jsp?from=ntes_nav®Page=163
A Http://reg.email.163.com/unireg/call.do?cmd=register.entrance&flow=mobile&from=ntes_nav
A http://mail.163.com/dashi/dlpro.html?from=mail46
A http://pay.163.com/
Use BeautifulSoup to retrieve www.163.com main Page all hyperlinks