【发布时间】:2018-11-19 13:37:41
【问题描述】:
希望将我用 beautifulsoup 提取的数据转换为 .csv 文件
这是要提取的代码:
from requests import get
url = 'https://howlongtobeat.com/game.php?id=38050'
response = get(url)
from bs4 import BeautifulSoup
html_soup = BeautifulSoup(response.text, 'html.parser')
game_name = html_soup.select('div.profile_header')[0].text
game_length = html_soup.select('div.game_times li div')[-1].text
game_developer = html_soup.find_all('strong', string='\nDeveloper:\n')[0].next_sibling
game_publisher = html_soup.find_all('strong', string='\nPublisher:\n')[0].next_sibling
game_console = html_soup.find_all('strong', string='\nPlayable On:\n')[0].next_sibling
game_genres = html_soup.find_all('strong', string='\nGenres:\n')[0].next_sibling
我想将这些结果写入 csv(它正在提取我想要的信息,但我认为它需要清理)
不确定如何写入 csv 或清理数据
请帮忙
【问题讨论】:
标签: python csv beautifulsoup