【发布时间】:2019-07-10 13:05:43
【问题描述】:
我无法提取一些特定标签(及其字符串内容)并将它们存储到变量中(这样我以后可以将这些变量放入 CSV 文件中)。
from bs4 import BeautifulSoup
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://www.khanacademy.org/profile/DFletcher1990/')
r.html.render(sleep=5)
soup=BeautifulSoup(r.html.html,'html.parser')
user_info_table=soup.find('table', class_='user-statistics-table')
for tr in user_info_table.find_all('tr'):
tds=tr.find_all('td')
print(tds)
我要收藏:
-
"4 years ago"并将其存储到一个名为date的变量中, -
"932,915"并将其存储到一个名为points的变量中, -
"372"并将其存储到名为videos的变量中。
我不太明白bs4.element.ResultSet 的行为...
【问题讨论】:
标签: python-3.x web-scraping beautifulsoup html-parsing