提取href链接

时间:2018-08-18 07:22:27

标签: python python-2.7

我编写了一个python代码,通过传递网址来提取没有https链接的href值。

from BeautifulSoup import BeautifulSoup
import urllib2
import re

html_page = urllib2.urlopen("http://kteq.in/index")
soup = BeautifulSoup(html_page)
for link in soup.findAll('a'):
    if link.get('href')==None:
       continue
    result = re.sub(r"http\S+", "", link.get('href'))
    print result 

运行上面的代码时,我提取了除https链接之外的所有href链接。得到以下输出。

index
index
#
solutions#internet-of-things
solutions#online-billing-and-payment-solutions
solutions#customer-relationship-management
solutions#enterprise-mobility
solutions#enterprise-content-management
solutions#artificial-intelligence
solutions#b2b-and-b2c-web-portals
solutions#robotics
solutions#augement-reality-virtual-reality
solutions#azure
solutions#omnichannel-commerce
solutions#document-management
solutions#enterprise-extranets-and-intranets
solutions#business-intelligence
solutions#enterprise-resource-planning
services
clients
contact
#
#
#
#myCarousel
#myCarousel

#
#
#
#
#
#
#
#
#
#
#step1
#step2
AndroidAppDevelopment
contact
solutions
contact

index
services
#
contact
#
iOSDevelopmentServices
AndroidAppDevelopment
WindowsAppDevelopment
HybridSoftwareSolutions
CloudServices
HTML5Development
iPadAppDevelopment
services
services
services
services
services
services
contact
contact
contact
contact
contact

#
#
#
#

现在,我需要提取上述输出链接中存在的href链接。例如,我需要从上述输出中提取“ index”内部的链接。请建议我获取输出。

0 个答案:

没有答案