title: Scraping text in h3 and p tags using beautifulsoup python
body: <p>I have experience with python, BeautifulSoup but I'm eager to scrape data from a website and store as a csv file. A single sample of data I need is coded as follows (a single row of data).</p>
  
  <pre><code>       ...body and not nested divs...       
              &lt;h3 class="college"&gt;
                  &lt;span class="num"&gt;1.&lt;/span&gt; &lt;a href="https://www.stanford.edu/"&gt;Stanford University&lt;/a&gt;
                  &lt;/h3&gt;
                  &lt;div class="he-mod" data-block="paragraph-9"&gt;&lt;/div&gt;
                  &lt;p class="school-location"&gt;Stanford, CA&lt;/p&gt;
               ...body and not nested divs...
          &lt;h3 id="MIT" class="college"&gt;
          &lt;span class="num"&gt;2.&lt;/span&gt; &lt;a href="https://web.mit.edu/"&gt;Massachusetts Institute of Technology (MIT)&lt;/a&gt;
          &lt;/h3&gt;
          &lt;div class="he-mod" data-block="paragraph-14"&gt;&lt;/div&gt;
          &lt;p class="school-location"&gt;Cambridge, MA&lt;/p&gt;
  ...body and not nested divs... 
      &lt;h3 id="Berkeley" class="college"&gt;
      &lt;span class="num"&gt;3.&lt;/span&gt; &lt;a href="https://www.berkeley.edu/"&gt;University of California Berkeley&lt;/a&gt;
      &lt;/h3&gt;
      &lt;div class="he-mod" data-block="paragraph-19"&gt;&lt;/div&gt;
      &lt;p class="school-location"&gt;Berkeley, CA&lt;/p&gt;
  ...body and not nested divs... 
  </code></pre>
  
  <p>I wish to get the links and name withing h3 and also text within <p>(i can do this but not the first part)
  However with my code I'm  only able to get Stanford though I'm find_all(class_='colleges')</p>
  
  <p>My Code</p>
  
  <pre><code>    import requests
  from bs4 import BeautifulSoup
  
  
  
  page = requests.get('https://thebestschools.org/features/best-computer-science-programs-in-the-world/')
  soup = BeautifulSoup(page.text, 'html.parser')
  
  
  college_name_list = soup.find(class_='college')
  college_name_list_items = college_name_list.find_all('a')
  for college_name in college_name_list_items:
      print(college_name.prettify())
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>&lt;a href="https://www.stanford.edu/"&gt;
      Stanford University
     &lt;/a&gt;
  </code></pre>
  
  <p>I wish to get the other colleges too with same class=college but different id's</p>
  
  <p>Please help me to just get them; i can arrange the .csv myself.</p>
  
  <p><a href="https://thebestschools.org/features/best-computer-science-programs-in-the-world/" rel="nofollow noreferrer">Source Website to be Scraped</a> if you can please tell me what div/class or anythhing i should look to!</p>