CSV文件中的数据一无所有
当我将数据打印到数据框中时,他们将在我制作CSV文件
时打印所有数据
import requests
from bs4 import BeautifulSoup
import pandas as pd
headers ={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'
}
r =requests.get('https://web.archive.org/web/20141113155415/http://www.alexa.com/topsites/category/Top/Recreation/Living_History/By_Historical_Region')
soup=BeautifulSoup(r.content, 'lxml')
main=soup.find_all('div',class_='desc-container')
web={}
for mains in main:
link=mains.find('p',class_='desc-paragraph').text
web['link']=link
des=mains.find('div',class_='description').text
web['description']=des
df = pd.DataFrame([web])
print(df)
WHEN I PRINT the data into data frame they will print all the data when I make the csv file
they will give me nothing in csv file
import requests
from bs4 import BeautifulSoup
import pandas as pd
headers ={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'
}
r =requests.get('https://web.archive.org/web/20141113155415/http://www.alexa.com/topsites/category/Top/Recreation/Living_History/By_Historical_Region')
soup=BeautifulSoup(r.content, 'lxml')
main=soup.find_all('div',class_='desc-container')
web={}
for mains in main:
link=mains.find('p',class_='desc-paragraph').text
web['link']=link
des=mains.find('div',class_='description').text
web['description']=des
df = pd.DataFrame([web])
print(df)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将带有数据的字典放入列表中,每次迭代都会创建新词典。例如:
打印:
并保存
data.csv
(从libreoffice屏幕截图):Try to put the dictionary with data into a list and each iteration create new dictionary. For example:
Prints:
and saves
data.csv
(screenshot from LibreOffice):