我正在寻找BeautifulSoup来检测链接中的NoFollow / DoFollow。是否有捷径可寻?我正在寻找一个忽略区分大小写的选项,并以不同的方式使用rel = nofollow。
我有这个,但它不起作用:
if 'nofollow' in link:
print "Nofollow"
else:
print "Dofollow"
编辑:其实我弄清楚了,这是代码:
if link in soup.find_all(rel="nofollow"):
print "NoFollow"
else:
print "Dofollow"
似乎它正在运行,我会更多地测试它并编辑是否需要例外。
答案 0 :(得分:0)
links = soup.find_all(rel=True) # This will find all links which has an attribute named 'rel'
for link in links:
print link['rel'] # This will print the value of rel attribute while looping through the earlier found links