我正试图用Python从Nordnet.no中抓取名称、上次库存和上次更新我已经为此做了一个函数,但我只得到第一个结果,而不是其他结果
import requests
import csv
from bs4 import BeautifulSoup
URL = 'https://www.nordnet.no/market/stocks?selectedTab=prices&page=2'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find('div', id='app')
#print(results.prettify())
stock_elems = results.find_all('table', attrs={'class':'c02352 c02354 md c02353'})
def finn():
for elem in stock_elems:
title_elem = elem.find('td', {'data-title': 'Navn'}) ## Navn
company_elem = elem.find('td', {'data-title': 'Siste'}) ## Siste
location_elem = elem.find('td', {'data-title': 'Tid'}) ## plassering
if None in (title_elem, company_elem, location_elem):
continue
print(title_elem.text.strip())
print(company_elem.text.strip())
print(location_elem.text.strip())
print()
finn()
据我所知,您没有在任何地方保存刮擦的结果。。。