Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to write beautifulsoup result to a file

Status
Not open for further replies.

leegold2

Technical User
Oct 10, 2004
116
0
0
If I try:
...
soup = BeautifulSoup(ft3)
f = open(r'c:\NewFolder\clean4.html', "w")
f.write(soup)
f.close()

I get error message:

Traceback (most recent call last):
File "C:\Documents and Settings\user01\Desktop\py\tb1a.py", line
203, in <module>
f.write(soup)
TypeError: expected a character buffer object

I want to write beautiful soup's result to a file, I am doing
something wrong. Help appreciated.

Thanks
 
Hi

Seems that [tt]write()[/tt] not calls [tt]__str__()[/tt] automatically. Just call it yourself : [tt]f[teal].[/teal]write[teal]([/teal][highlight]str[teal]([/teal][/highlight]soup[highlight][teal])[/teal][/highlight][teal])[/teal][/tt].


Feherke.
 
personally when writing out i would use f.write (soup.prettify()) as this results in a nice readable output.


Computers are like Air conditioners:-
Both stop working when you open Windows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top