python BeautifulSoup獲取 網頁鏈接的文字內容


這裏和 獲取鏈接略有不同,不是得到鏈接到url,而是獲取每個鏈接的文字內容


#!/opt/yrd_soft/bin/python

import re
import urllib2
import requests
import lxml
from bs4 import BeautifulSoup

url = 'http://www.baidu.com'

#page=urllib2.urlopen(url)
page=requests.get(url).text
pagesoup=BeautifulSoup(page,'lxml')
for link  in pagesoup.find_all(name='a',attrs={"href":re.compile(r'^http:')}):
    print link.get_text()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章