Python 在同一行和返回路径上查找多个链接
我想从HTML页面或文本文件中找到同一行上的多个链接,并返回路径。 目前,我设法在这条线上找到第一个链接,但当我在同一条线上有两个链接时,它不起作用,我找不到解决方案,所以我需要一些帮助Python 在同一行和返回路径上查找多个链接,python,find,Python,Find,我想从HTML页面或文本文件中找到同一行上的多个链接,并返回路径。 目前,我设法在这条线上找到第一个链接,但当我在同一条线上有两个链接时,它不起作用,我找不到解决方案,所以我需要一些帮助 def get_href(line) : x = line.find('href=') if x < 0 : return ref = line[x+6:].split('"')[0] if ref.startswith('http:') : return ref
def get_href(line) :
x = line.find('href=')
if x < 0 : return
ref = line[x+6:].split('"')[0]
if ref.startswith('http:') : return ref
hrefs = []
flux = urlopen('http://www.python.org/')
for line in flux : hrefs.append(get_href(line))
def get_href(行):
x=line.find('href='))
如果x<0:返回
ref=第[x+6:]行。拆分(“”)[0]
if ref.startswith('http:'):返回ref
hrefs=[]
通量=urlopen('http://www.python.org/')
对于通量中的行:hrefs.append(get_href(line))
我尝试了这个,我认为它是有效的:
def get_href(line) :
tab = []
link = []
x = line.find('href=')
if x < 0: pass
else :
tab = line.split('"')
for ref in tab:
if ref.startswith('http:') or ref.startswith('https:') : link.append(ref)
print link
def get_href(行):
tab=[]
链接=[]
x=line.find('href='))
如果x<0:通过
其他:
tab=行。拆分(“”)
对于选项卡中的ref:
如果ref.startswith('http:')或ref.startswith('https:'):link.append(ref)
打印链接
显示行
内容如何在“href”
上拆分ligne
?该行
内容来自任何网站或页面。我得到每行的字符串。