i want to scrape data using python script
<p>I have written python script to scrape data from <a href="http://www.cricbuzz.com/cricket-stats/icc-rankings/batsmen-rankings" rel="nofollow">http://www.cricbuzz.com/cricket-stats/icc-rankings/batsmen-rankings</a> 
It is a list of 100 players and I successfully scraped this data. The problem is, when i run script instead of scraping data just one time it scraped the same data 3 times.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="cb-col cb-col-100 cb-font-14 cb-lst-itm text-center"&gt;
  &lt;div class="cb-col cb-col-16 cb-rank-tbl cb-font-16"&gt;1&lt;/div&gt;
  &lt;div class="cb-col cb-col-50 cb-lst-itm-sm text-left"&gt;
    &lt;div class="cb-col cb-col-33"&gt;
      &lt;div class="cb-col cb-col-50"&gt;
        &lt;span class=" cb-ico" style="position:absolute;"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;â
      &lt;/div&gt;
      &lt;div class="cb-col cb-col-50"&gt;
        &lt;img src="http://i.cricketcb.com/i/stats/fw/50x50/img/faceImages/2250.jpg" class="img-responsive cb-rank-plyr-img"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="cb-col cb-col-67 cb-rank-plyr"&gt;
      &lt;a class="text-hvr-underline text-bold cb-font-16" href="/profiles/2250/steven-smith" title="Steven Smith's Profile"&gt;Steven Smith&lt;/a&gt;
      &lt;div class="cb-font-12 text-gray"&gt;AUSTRALIA&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="cb-col cb-col-17 cb-rank-tbl"&gt;906&lt;/div&gt;
  &lt;div class="cb-col cb-col-17 cb-rank-tbl"&gt;1&lt;/div&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>And here is python script which i write scrap each player data.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import sys,requests,csv,io
from bs4 import BeautifulSoup
from urllib.parse import urljoin

url = "http://www.cricbuzz.com/cricket-stats/icc-rankings/batsmen-rankings"
r = requests.get(url)
r.content
soup = BeautifulSoup(r.content, "html.parser")

maindiv = soup.find_all("div", {"class": "text-center"})
for div in maindiv:
	print(div.text)</code></pre>
</div>
</div>
</p>

<p>but instead of scraping the data once, it scrapes the same data 3 times.</p>

<p>Where can I make changes to get data just one time?</p>

<p>Select the table and look for the divs in that:</p>

<pre><code>maindiv = soup.select("#batsmen-tests div.text-center")
for div in maindiv:
    print(div.text)
</code></pre>

<p>Your original output and that above gets all the text from the divs as one line which is not really useful, if you just want the player names:</p>

<pre><code>anchors = soup.select("#batsmen-tests div.cb-rank-plyr a")
for a in anchors:
    print(a.text)
</code></pre>

<p>A quick and easy way to get the data in a nice csv format is to just get text from each child:</p>

<pre><code>maindiv = soup.select("#batsmen-tests div.text-center")
for d in maindiv[1:]:
    row_data = u",".join(s.strip() for s in filter(None, (t.find(text=True, recursive=False) for t in d.find_all())))
    if row_data:
        print(row_data)
</code></pre>

<p>Now you get output like:</p>

<pre><code># rank, up/down, name, country, rating, best rank
1,â,Steven Smith,AUSTRALIA,906,1
2,â,Joe Root,ENGLAND,878,1
3,â,Kane Williamson,NEW ZEALAND,876,1
4,â,Hashim Amla,SOUTH AFRICA,847,1
5,â,Younis Khan,PAKISTAN,845,1
6,â,Adam Voges,AUSTRALIA,802,5
7,â,AB de Villiers,SOUTH AFRICA,802,1
8,â,Ajinkya Rahane,INDIA,785,8
9,2,David Warner,AUSTRALIA,772,3
10,â,Alastair Cook,ENGLAND,770,2
11,1,Misbah-ul-Haq,PAKISTAN,764,6
</code></pre>

<p>As opposed to:</p>

<pre><code>PositionPlayerRatingBest Rank
Player
1Â Â Â Â âSteven SmithAUSTRALIA9061
2Â Â Â Â âJoe RootENGLAND8781
3Â Â Â Â âKane WilliamsonNEW ZEALAND8761
4Â Â Â Â âHashim AmlaSOUTH AFRICA8471
5Â Â Â Â âYounis KhanPAKISTAN8451
6Â Â Â Â âAdam VogesAUSTRALIA8025
</code></pre>

python html5 python-3.x beautifulsoup python-3.4