Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
html parser
#1
Hello - I'm working on the book "Web Scraping with Python" b Ryan Mitchell 2015.

I finally just decided to pick one and jump in so here I am. I've got the basics (I think). There is still much to learn I'm sure. Here's my current issue...

from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsOb = BeautifulSoup(html.read())
print(bsObj.h1)

This is the error I get...

Warning (from warnings module):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__init__.py", line 181
markup_type=markup_type))
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 1 of the file <string>. To get rid of this warning, change code that looks like this:

BeautifulSoup(YOUR_MARKUP})

to this:

BeautifulSoup(YOUR_MARKUP, "html.parser")

Traceback (most recent call last):
File "C:\Python\Web Scraping pg 8.py", line 5, in <module>
print(bsObj.h1)
NameError: name 'bsObj' is not defined


from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsOb = BeautifulSoup(html.read, html.parser)
print(bsObj.h1)

This is the error I get...

Traceback (most recent call last):
File "C:\Python\Web_Scraping_pg_8.py", line 4, in <module>
bsOb = BeautifulSoup(html.read, html.parser)
AttributeError: 'HTTPResponse' object has no attribute 'parser'


I think the reason I'm having the issue is because of the age of the book. Any help I can get would be most appreciated!

Thank you!! Smile
Reply


Messages In This Thread
html parser - by tjnichols - Mar-16-2018, 06:13 PM
RE: html parser - by snippsat - Mar-16-2018, 06:16 PM
RE: html parser - by nilamo - Mar-16-2018, 07:31 PM
RE: html parser - by tjnichols - Mar-17-2018, 05:08 PM
RE: html parser - by buran - Mar-16-2018, 07:31 PM
RE: html parser - by metulburr - Mar-16-2018, 07:38 PM
RE: html parser - by snippsat - Mar-17-2018, 05:55 PM
RE: html parser - by tjnichols - Mar-17-2018, 06:28 PM
RE: html parser - by tjnichols - Mar-17-2018, 08:43 PM
RE: html parser - by tjnichols - Mar-17-2018, 11:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,688 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Easy HTML Parser: Validating trs by attributes several tags deep? runswithascript 7 3,634 Aug-14-2020, 10:58 PM
Last Post: runswithascript
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,393 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Django field model for HTML parser? Drone4four 0 4,174 Nov-15-2017, 02:43 AM
Last Post: Drone4four

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020