Web Scrape Error

已查看 47 次
跳至第一个未读帖子

j sao

未读,
2016年4月4日 09:11:042016/4/4
收件人 beautifulsoup

i am very noob here beginner of python. I use mechanize & beautiful soup to write some code as below:

from mechanize import Browser
from bs4 import BeautifulSoup as BS

br = Browser()

# Browser options
# Ignore robotx.
br.set_handle_robots(False)

br.set_handle_referer(False)

br.set_handle_referer(False)

br.addheaders = [('User-agent', 'Firefox')]

br.open('http://www.amazon.in/')
br.select_form(name='site-search')
br['field-keywords'] = 'Blackberry'
br.submit()

soup = BS(br.response().read())

for product in soup.find_all('h3', class_='newaps'):
    print "Product Name:" + product.a.text
    print "Product Url:" + product.a["href"]

But in powershell,when i run the code this is the error i got:

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")

Any idea what's happening here??Please help:-)



And i am using Windows

Elizabeth Frazier

未读,
2016年4月7日 12:11:352016/4/7
收件人 beautifulsoup
Hi,

You need to define which parser you want Beautiful Soup to use. br.response().read() is your marke up. After that you need to explicitly define "html.parser" as your parser. "html.parser" is the basic parser, but there are others you can select from.  For more information:
回复全部
回复作者
转发
0 个新帖子