我正在尝试抓取一个web应用程序,我只想打印与文本“在图表上显示”相关联的href链接。
这里是我试图打印的html的截图:
web应用程序代码
这是我正在使用的python代码:
import webbrowser
from bs4 import BeautifulSoup
import requests
def cllicheck(clli): #checks to see if there is exactly 8 characters in the clli input
#print "in the clli checker"
if len(clli) == 8:
return True
else:
print('Invalid CLLI')
return
def drawing(CLLI):
if cllicheck(CLLI) == True:
CLLIstate = CLLI[4:6]
#print "------- Netviz", NetvizCLLI, "was entered ----------"
resultStr = 'https://gpn.prod.att.com/netTerrain/Search?q=' + CLLI + '&subDiagrams=False&exactMatch=False&filter=Title'
webbrowser.open(resultStr)
r = requests.get(resultStr)
soup = BeautifulSoup(r.content, 'html.parser')
for link in soup.find_all('a', 'Show on diagram', href=True):
print (link['href'])
main()
else:
print ('Please Enter 8 Characters')
main()
def main ():
#Beginning function to prompt user for CLLI
print ('\nPlease Enter CLLI.\n')
CLLI = input()
drawing(CLLI)
main() #This begins the GPN Program
当我运行这个时,它什么都没有打印出来。
我使用这部分代码希望返回href链接:
for link in soup.find_all('a', 'Show on diagram', href=True):
print (link['href'])
我希望在运行此代码时显示/打印网络截图上显示的链接