【发布时间】:2021-02-04 20:18:35
【问题描述】:
此代码的输出打印下面提供的网站上的每一行。
但它也包含标签。本质上,我想将所有行打印到一个 dataFrame 中,我可以把它放在 Excel 上。
.text 不起作用,因为我使用的是 find_all,因为有些标签在名称中重复。
如何删除不需要的标签,然后将列表放入 DF,复制网站?
谢谢。
import requests
from bs4 import BeautifulSoup
import pandas as pd
productlinks=[]
r=requests.get(url)
soup= BeautifulSoup(r.content,'html.parser')
content=soup.find_all('tr')
for item in content:
title=item.find_all('td')
print(title)
【问题讨论】:
-
pd.read_html()和 this answer 一样吗? -
我收到此错误-引发 ImportError("lxml not found, please install it") ImportError: lxml not found, please install it
-
谢谢你,这行得通
标签: python html pandas dataframe beautifulsoup