Going through HTML DOM in Python

后端 未结 2 1742
南旧
南旧 2021-01-03 02:10

I\'m looking to write a Python script (using 3.4.3) that grabs a HTML page from a URL and can go through the DOM to try to find a specific element.

I currently have

2条回答
  •  时光说笑
    2021-01-03 02:25

    Check out the BeautifulSoup module.

    from bs4 import BeautifulSoup
    import urllib                                       
    soup = BeautifulSoup(urllib.urlopen("http://google.com").read())
    
    for link in soup.find_all('a'):
        print(link.get('href'))
    

提交回复
热议问题