Python,BeautifulSoup-仅打印包含<;img>;内容
是否可以在beautifulSoup中设置为只能打印内容中包含Python,BeautifulSoup-仅打印包含<;img>;内容,python,beautifulsoup,Python,Beautifulsoup,是否可以在beautifulSoup中设置为只能打印内容中包含的链接 当前我的代码如下所示: import urllib import re import mechanize from bs4 import BeautifulSoup import urlparse url = "http://www.nytimes.com" htmlcontent = urllib.urlopen(url) soup = BeautifulSoup(htmlcontent) for link in sou
的链接
当前我的代码如下所示:
import urllib
import re
import mechanize
from bs4 import BeautifulSoup
import urlparse
url = "http://www.nytimes.com"
htmlcontent = urllib.urlopen(url)
soup = BeautifulSoup(htmlcontent)
for link in soup.find_all('a'):
print link.contents
打印出链接内的所有内容。但我真正需要的是打印在内容中有
标记的链接,我不知道怎么做
欢迎提供任何帮助只要尝试在链接中查找
img
标签即可:
for link in soup.find_all('a'):
if link.find('img'):
print link
只需在链接中找到
img
标记即可:
for link in soup.find_all('a'):
if link.find('img'):
print link