这是我试过的:
import requests
website_url = "https://en.wikipedia.org/wiki/List_of_Texas_Rangers_seasons"
url = requests.get(website_url).text
from bs4 import BeautifulSoup
soup = BeautifulSoup(website_url,'html.parser')
# Selecting the table
table_classes = {"class":"wikitable plainrowheaders"}
rel_table = soup.find_all('table',table_classes)
我不知道如何进一步。我确实检查了元素,看起来标题和href都是动态的,包含年份字段。同时,它还包含华盛顿参议员的表格。我将不胜感激任何帮助!谢谢!
from bs4 import BeautifulSoup
import requests
url = 'https://en.wikipedia.org/wiki/List_of_Texas_Rangers_seasons'
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
#method 1
for row in soup.select('table.plainrowheaders tr')[14:]:
for cell in row.select('td'):
print(cell.text.strip(), end=' ')
print()
#method 2
for row in soup.select('table.plainrowheaders tr')[14:]:
print(row.get_text(strip=True, separator=' '))