如何检索网页链接并使用Python复制链接的URL地址?
这是在BeautifulSoup中使用SoupStrainer类的一小段代码:
BeautifulSoup
SoupStrainer
import httplib2 from BeautifulSoup import BeautifulSoup, SoupStrainer http = httplib2.Http() status, response = http.request('http://www.nytimes.com') for link in BeautifulSoup(response, parse_only=SoupStrainer('a')): if link.has_attr('href'): print(link['href'])