0

I am using Python 3.7.0 I am not able to use BeautifulSoup attribute of bs4

I have reinstalled the library but is still not working.

from bs4 import BeautifulSoup
import csv
html = open("table.html").read()
soup = BeautifulSoup(html)
table = soup.find("table")

output_rows = []
for table_row in table.findAll('tr'):
    columns = table_row.findAll('td')
    output_row = []
    for column in columns:
        output_row.append(column.text)
    output_rows.append(output_row)

with open('output.csv', 'wb') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows(output_rows)

it is throwing following error:

Traceback (most recent call last):
  File "D:\Automation\ReadHtml\html.py", line 1, in <module>
    from bs4 import BeautifulSoup
  File "D:\Python37\lib\site-packages\bs4\__init__.py", line 34, in <module>
    from .builder import builder_registry, ParserRejectedMarkup
  File "D:\Python37\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
    from bs4.element import (
  File "D:\Python37\lib\site-packages\bs4\element.py", line 19, in <module>
    from bs4.formatter import (
  File "D:\Python37\lib\site-packages\bs4\formatter.py", line 1, in <module>
    from bs4.dammit import EntitySubstitution
  File "D:\Python37\lib\site-packages\bs4\dammit.py", line 13, in <module>
    from html.entities import codepoint2name
  File "D:\Automation\ReadHtml\html.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup' from 'bs4' (D:\Python37\lib\site-packages\bs4\__init__.py)

Edit:

I installed using

pip install BeautifulSoup4

also installed

pip install bs4

but it is still not working.

RobC
  • 22,977
  • 20
  • 73
  • 80
Sushit Kumar
  • 31
  • 1
  • 5
  • 1
    Please check this link I think, it will surely help you. https://stackoverflow.com/questions/29907405/cannot-import-beautiful-soup This question is probably a duplicate. – Tajinder Jul 25 '19 at 10:09

1 Answers1

2

Soved Thanks, just renamed the file from html.py to something.py

Sushit Kumar
  • 31
  • 1
  • 5