我正在尝试在href中查找包含“.ics”的URL。前几天我测试了这个代码,它运行得很好,但是现在当我尝试搜索“链接中的链接”时,“打印链接”的结果是:``
<a class="element-invisible element-focusable" href="#main-content"
tabindex="1">Skip to main content</a>
<a class="element-invisible element-focusable" href="#main-content">Skip to
main content</a>
因此,如果链接。获取('href')'代码永远不会满足,并且不会返回URL。是什么导致了这种情况,是否有其他方法返回包含“.ics”的URL?你知道吗
page = requests.get('https://registrar.fas.harvard.edu/calendar').content
soup = bs4.BeautifulSoup(page, 'lxml')
links = soup.find_all('a')
#print links
for link in links:
print link
if link.get('href') != None and '.ics' in link.get('href'):
endout = link.get('href')
if endout[:6] == 'webcal':
endout ='https' + endout[6:]
print
print 'URL: ' + endout
print
return endout
break
我建议通过传递css
href
选择器和regex模式来简化搜索:输出:
你现在就不需要跳转来验证你的锚定标签了。你知道吗
相关问题 更多 >
编程相关推荐