Getting attribute's value using BeautifulSoup

后端 未结 3 2037
予麋鹿
予麋鹿 2020-12-30 10:57

I\'m writing a python script which will extract the script locations after parsing from a webpage. Lets say there are two scenarios :



        
3条回答
  •  时光说笑
    2020-12-30 11:41

    Get 'src' from script node.

    import requests 
    from bs4 import BeautifulSoup
    
    r  = requests.get("http://rediff.com/")
    data = r.text
    soup = BeautifulSoup(data)
    for n in soup.find_all('script'):
        print "src:", n.get('src') <==== 
    

提交回复
热议问题