Python从网站获取数据

时间:2017-02-08 18:13:27

标签: python-2.7

下面的python代码无法从给定链接获取数据。请帮助我如何使它成为可能

 import urllib2
 from bs4 import BeautifulSoup
  quote_page = 'http://www.smartvidya.co.in/2016/11/ugc-net-paper-1-previous-year-questions_14.html'
 page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
name_box = soup.find('div', attrs={'class': 'MsoNormal'})

print name_box

1 个答案:

答案 0 :(得分:1)

试试这个:

import urllib2
from bs4 import BeautifulSoup
quote_page = 'http://www.smartvidya.co.in/2016/11/ugc-net-paper-1-previous-year-questions_14.html'
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
for name_box in soup.findAll('div',attrs={'class': 'MsoNormal'}):
    print name_box.text

希望这有帮助!