Get meta tag content property with BeautifulSoup and Python

后端 未结 4 1013
遇见更好的自我
遇见更好的自我 2021-01-30 16:43

I am trying to use python and beautiful soup to extract the content part of the tags below:


&l         


        
4条回答
  •  既然无缘
    2021-01-30 16:46

    A way I like to solve this is as follows:
    (Is neater when using with lists of properties to look up...)

    title = soup.find("meta",  {"property":"og:title"})
    url = soup.find("meta",  {"property":"og:url"})
    
    # Using same method as above answer
    title = title["content"] if title else None
    url = url["content"] if url else None
    

提交回复
热议问题