我有一個代碼從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