简体   繁体   中英

extract data from website using Bautifulsoup in python

I'm trying to extract data from website http://www.bcsfootball.org

In this website I'm looking to extract Welcome block with all text in it.

Here is my code

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)

error

    for row in soup('table',{'class':mod-container mod-no-footer mod-open'})[0].tbody('tr'):
                                                     ^
SyntaxError: invalid syntax

Please anyone can help me where am doing wrong ? I'm new to python

Please also help me to understand [0].tbody('tr'): in code. What its doing exactly ?

Thanks

this code should work, you were missing an apostrophe.

Code:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM