title: Looping through web pages
body: <p>I am running a script to update product prices by scraping them from a website. The script should scrape all names and prices for a given page and then move on to the next page. However, instead of moving on to the next page it keeps looping through the same page for some reason. I tried many variations of the code but it still keeps happening.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>page_B = 1
  url_B = 'https://website/section/food-drink?page=1/'  # Initial url
  
  while page_B &lt; 15:
      req = Request(url_B, headers={'User-Agent': 'Chrome'})
      web_page = urlopen(req).read()
      soup = BeautifulSoup(web_page, "html.parser")
  
      for product in soup.find_all('div', class_="product-wrapper"):
          # Get product name
          product_title = product.find('p', class_='h4 product__title').text
          # Get product price
          product_price = product.find('p', class_='product__price')
          raw_data = list(product_price.children)[-1]
          # Remove spaces, newlines and quotes from prices
          clean_price = raw_data.strip(' \n"')
  
          print(product_title)
          print(clean_price)
  
          csv_writer.writerow([product_title, product_price])
  
      url_base = url_B.split(str(page_B))
      page_B += 1
      new_url = url_base[0] + str(page_B) + '/'
      url_B = new_url
  
  csv_file.close()
  
  </code></pre>
  
  <p>The last portion of the code is where I instruct the script to update the url for the next page. When I run this program it is printing me product names and prices 15 times for the same page. I suspect the issue has something to do with local vs global variables, but I'm quite new to programming, so still a bit confused. Any help is appreciated.</p>