TypeError: argument 1 must be convertible to a buffer, not BeautifulSoup
<pre><code>from bs4 import BeautifulSoup
import requests
import csv


page=requests.get("http://www.gigantti.fi/catalog/tietokoneet/fi_kannettavat/kannettavat-tietokoneet")

data=BeautifulSoup(page.content)

h=open("test.csv","wb+")
h.write(data)
h.close()

print (data)
</code></pre>

<p>i have tried running the code as it is without printing it in csv file and it runs perfectly but the moment I try to save it in csv I get the error : argument 1 must be convertible to a buffer, not BeautifulSoup. PLEASE HELP and thanks in advance</p>

<p>What you are trying to do doesn't make any sense.</p>

<p>As mentioned on <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">Beautiful Soup Documentation</a>:</p>

<blockquote>
  <p>Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work.</p>
</blockquote>

<p>You do not seem to be pulling any data but you are trying to write a <code>BeautifulSoup</code> object into a file which doesn't make sense.</p>

<pre><code>&gt;&gt;&gt; type(data)
&lt;class 'bs4.BeautifulSoup'&gt;
</code></pre>

<p>What you should be using <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow"><code>BeautifulSoup</code></a> for is to search the data for some information, and then use that information, here's a useless example:</p>

<pre><code>from bs4 import BeautifulSoup
import requests
page = requests.get("http://www.gigantti.fi/catalog/tietokoneet/fi_kannettavat/kannettavat-tietokoneet")

data = BeautifulSoup(page.content)
with open("test.txt", "wb+") as f:
   # find the first `&lt;title&gt;` tag and retrieve its value 
   value = data.findAll('title')[0].text
   f.write(value)
</code></pre>

<p>It seems like you should be using <code>BeautifulSoup</code> to be retreiving all the information on each product in the product listing and putting them into columns in a csv file if I'm guessing correctly, but I will leave that work up to you. You must use <code>BeautifulSoup</code> to find each product in the <code>html</code> and then retrieve all of its details and print to a csv</p>

python csv web-scraping