[英]extract data from website using Bautifulsoup in python
我正在嘗試從網站http://www.bcsfootball.org中提取數據
在這個網站上,我希望提取包含所有文本的歡迎塊。
這是我的代碼
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://www.bcsfootball.org').read())
for row in soup('table',{'class':mod-container mod-no-footer mod-open'})[0].tbody('tr'):
tds = row('td')
print (tds[0].string, tds[1].string)
錯誤
for row in soup('table',{'class':mod-container mod-no-footer mod-open'})[0].tbody('tr'):
^
SyntaxError: invalid syntax
請有人可以幫助我在哪里做錯了? 我是python的新手
還請幫我理解[0] .tbody('tr'):代碼。 它究竟做了什么?
謝謝
這段代碼應該有用,你錯過了一個撇號。
碼:
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://www.bcsfootball.org').read())
for row in soup('table',{'class':'mod-container mod-no-footer mod-open'})[0].tbody('tr'):
tds = row('td')
print (tds[0].string, tds[1].string)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.