我有一个代码从ESPN NCAA网站提取头条新闻。但我想刮掉整个WEBPAGE。我是一个编程新手,所以如果你能帮助刮网页真的很感激。我发现很难理解XML标签并识别它们。你们中的任何人都可以修改此代码,以便打印此网页上的全部或大部分内容吗?谢谢!如何从网页刮擦身体?
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import smtplib
site = urlopen('http://espn.go.com/college-football').read()
soup = BeautifulSoup(site)
for i in soup.findAll('ul', {'class': 'headlines'}):
for tag in i.findAll('li'):
for a in tag.findAll({'a' : True, 'title' : False}):
print a.text
print a['href']
print "\n"
代码看起来不错。你有什么具体问题吗? – bernie
是的。我想问的是,上面的代码只能提取标题。我如何使它提取网页中的所有文字? – user2237900