首页 > 解决方案 > 我在 beautifulsoup 中找不到表

问题描述

所以我对这些东西真的很陌生,所以这可能很愚蠢。但我似乎无法弄清楚为什么这个非常基本的代码行找不到任何表格......还试图找到一个表格来基本上获取每一行。网址:https ://uwflow.com/course/cs136

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = "https://uwflow.com/course/cs136"

# opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

# html parser
page_soup = soup(page_html, "html.parser")

    enter code here

table = page_soup.findAll('table')
print(table)

标签: pythonbeautifulsoup

解决方案


from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import pandas as pd

options = Options()
options.add_argument('--headless')

driver = webdriver.Firefox(options=options)
driver.get("https://uwflow.com/course/cs136")

df = pd.read_html(driver.page_source)[0]

df.to_csv('out.csv', index=False)

driver.quit()

输出:在线查看

我已经采取了Winter 2020,如果你愿意的话Spring 2020,你需要更改[0][1]


推荐阅读