title: Scrape multiple pages with BeautifulSoup and Python
body: <p>My code successfully scrapes the tr align=center tags from [ <a href="http://my.gwu.edu/mod/pws/courses.cfm?campId=1&amp;termId=201501&amp;subjId=ACCY">http://my.gwu.edu/mod/pws/courses.cfm?campId=1&amp;termId=201501&amp;subjId=ACCY</a> ] and writes the td elements to a text file. </p>
  
  <p>However, there are multiple pages available at the site above in which I would like to be able to scrape. </p>
  
  <p>For example, with the url above, when I click the link to "page 2" the overall url does NOT change. I looked at the page source and saw a javascript code to advance to the next page. </p>
  
  <p>How can my code be changed to scrape data from all the available listed pages? </p>
  
  <p>My code that works for page 1 only:</p>
  
  <pre><code>import bs4
  import requests 
  
  response = requests.get('http://my.gwu.edu/mod/pws/courses.cfm?campId=1&amp;termId=201501&amp;subjId=ACCY')
  
  soup = bs4.BeautifulSoup(response.text)
  soup.prettify()
  
  acct = open("/Users/it/Desktop/accounting.txt", "w")
  
  for tr in soup.find_all('tr', align='center'):
      stack = []
      for td in tr.findAll('td'):
          stack.append(td.text.replace('\n', '').replace('\t', '').strip())
  
      acct.write(", ".join(stack) + '\n')
  </code></pre>