How can I get href links from HTML using Python?

后端 未结 10 2310
自闭症患者
自闭症患者 2020-11-27 03:25
import urllib2

website = \"WEBSITE\"
openwebsite = urllib2.urlopen(website)
html = getwebsite.read()

print html

So far so good.

But I wa

10条回答
  •  佛祖请我去吃肉
    2020-11-27 03:49

    Using requests with BeautifulSoup and Python 3:

    import requests 
    from bs4 import BeautifulSoup
    
    
    page = requests.get('http://www.website.com')
    bs = BeautifulSoup(page.content, features='lxml')
    for link in bs.findAll('a'):
        print(link.get('href'))
    

提交回复
热议问题