1
我想創建一個函數,它將從給定的URL中提取元關鍵字並將其返回。然而,無論我傳遞給它什麼URL,它總是會失敗。BeautifulSoup無法提取元數據
def GetKeywords(url):
soup = BeautifulSoup(url)
keywords = soup.findAll('meta', attrs={'name':re.compile("^keywords$", re.I)}) #Find all meta keywords on that page
if len(keywords) == 0: #Check to see if that page has any meta keywords to begin with
print "No meta keywords for: " + str(url)
return -1
else: #If so then return them
return keywords
感謝您的答覆,我今天剛剛開始學習python,我嘗試閱讀BS文檔,但並不完全理解它。再次感謝,非常感謝。 – Mhoad 2011-05-22 11:37:47