0

Hello everyone, new Python user here I am having a strange error when building a very basic page scraper.

I am using BeautifulSoup4 to assist me and when I execute my code I get this error

"UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 13 of the file C:/Users/***/PycharmProjects/untitled1/s.py. To get rid of this warning, change code that looks like this:"

 BeautifulSoup([your markup])

to this:

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

  markup_type=markup_type))

If anyone has any help to fix this I would greatly appreciate it!

Code Follows

import requests
from bs4 import BeautifulSoup

def trade_spider():
    url = 'http://buckysroom.org/trade/search.php?page=' # Could add a + pls str(pagesomething) to add on to the url so that it would update
    source_code = requests.get(url) #requests the data from the site
    plain_text = source_code.text #imports all of the data gathered
    soup = BeautifulSoup(plain_text) #This hold all of the data, and allows you to sort through all of the data, converts it
    for link in soup.find_all( 'a', {'class' : 'item-name'}):
        href = link.get('href')
        print(href)

trade_spider()
Noah Linton
  • 11
  • 1
  • 8
  • 1
    Possible duplicate of [How to get rid of BeautifulSoup user warning?](http://stackoverflow.com/questions/33511544/how-to-get-rid-of-beautifulsoup-user-warning) – matias elgart Dec 03 '16 at 20:59

1 Answers1

0

You could try to change the following line to:

soup = BeautifulSoup(plain_text, "html.parser")

or whatever other parser you need to use...

coder
  • 12,832
  • 5
  • 39
  • 53
  • That worked perfectly! Could you please explain why it worked? – Noah Linton Dec 03 '16 at 21:31
  • @NoahLinton, as far as I know BeautifulSoup needs a parser specified to be able to recognize better the web content you provide and produce correct parsing results. If you check the link in my post you will see that there are other parsers also for different kind of content. For more info: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#specifying-the-parser-to-use – coder Dec 03 '16 at 21:34