I'm creating a web-scraper and am trying to request multiple urls that share the same url path except for a numbered id.
My code to scrape one url is as follows:
import requests
from bs4 import BeautifulSoup as bs
r = requests.get('https://beta.companieshouse.gov.uk/company/00930291/officers')
soup = bs(r.content, 'lxml')
names = [item.text.strip() for item in soup.select('[class^=appointment]:not(.appointments-list):has([id^="officer-role-"]:contains(Director)) h2')]
print(names)
The url shares the same structure except for the company numbers. I've tried the following code to try and get it to scrape multiple pages, but without success:
import requests
from bs4 import BeautifulSoup as bs
pages = []
for i in range(11003058, 11003059, 00930291):
```url = 'https://beta.companieshouse.gov.uk/company/' + str(i) + '/officers'
```pages.append(url)
for item in pages:
```page = requests.get(item)
```soup = bs(page.text, 'lxml')
names = [item.text.strip() for item in soup.select('[class^=appointment]:not(.appointments-list):has([id^="officer-role-"]:contains(Director)) h2')]
print(names)
This is only giving me the first page (/11003058/officers), why is it not looping through them? Can anyone help?