car_names = soup.find_all("h3") for name in car_names: print(name.text)
我需要将名称.文本保存到 Dataframe 中?
qyswt5oh1#
import pandas as pd names = [] for name in car_names: names.append(name.text) df =pd.DataFrame(data = names, columns = ['car_name'])
ev7lccsx2#
您可以使用下一个示例如何从HTML数据创建PandasDataFrame:
import pandas as pd from bs4 import BeautifulSoup html_doc = """ <h3>Ford</h3> <h3>Toyota</h3> <h3>Škoda</h3> """ soup = BeautifulSoup(html_doc, "html.parser") car_names = soup.find_all("h3") data = [] for name in car_names: data.append({"Car Name": name.text}) df = pd.DataFrame(data) print(df)
图纸:
Car Name 0 Ford 1 Toyota 2 Škoda
ar7v8xwq3#
我想你在找这个
import pandas as pd car_names = soup.find_all("h3") res = [name.text for name in car_names] df = pd.DataFrame(res) print(df)
3条答案
按热度按时间qyswt5oh1#
ev7lccsx2#
您可以使用下一个示例如何从HTML数据创建PandasDataFrame:
图纸:
ar7v8xwq3#
我想你在找这个