Мне удалось написать код для очистки данных с первой страницы, и теперь я застрял в написании цикла в этом коде для очистки следующих 'n' страниц.Ниже приведен код
. Буду признателен, если кто-нибудь поможет мне написать / напишет код, который будет очищать данные с оставшихся страниц.
Спасибо!
from bs4 import BeautifulSoup
import requests
import csv
url = requests.get('https://wsc.nmbe.ch/search?sFamily=Salticidae&fMt=begin&sGenus=&gMt=begin&sSpecies=&sMt=begin&multiPurpose=slsid&sMulti=&mMt=contain&searchSpec=s').text
soup = BeautifulSoup(url, 'lxml')
elements = soup.find_all('div', style="border-bottom: 1px solid #C0C0C0; padding: 10px 0;")
#print(elements)
csv_file = open('wsc_scrape.csv', 'w')
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['sp_name', 'species_author', 'status', 'family'])
for element in elements:
sp_name = element.i.text.strip()
print(sp_name)
status = element.find('span', class_ = ['success label', 'error label']).text.strip()
print(status)
author_family = element.i.next_sibling.strip().split('|')
species_author = author_family[0].strip()
family = author_family[1].strip()
print(species_author)
print(family)
print()
csv_writer.writerow([sp_name, species_author, status, family])
csv_file.close()