python 比较美国和印度Netflix系列| Excel文件:https://goo.gl/JZMb3C

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 比较美国和印度Netflix系列| Excel文件:https://goo.gl/JZMb3C相关的知识,希望对你有一定的参考价值。

from urllib.request import urlopen
from bs4 import BeautifulSoup as bs
import csv as csv

url = 'http://www.finder.com/in/netflix-india-vs-netflix-us-titles-list'
html = urlopen(url).read()

soup = bs(html, "lxml")
table = soup.find('table', id='tablepress-9')

data = []
headers = ['Title', 'Year', 'Type', 'India', 'USA']
data.append(headers)

#extract text from markup
for row in table.findAll('tr')[1:]:
    col = row.findAll('td')
    col = [ele.text.strip() for ele in col]
    data.append([ele for ele in col if ele])
    
#write to a csv file    
with open('./data/netflix.csv', 'w', newline='') as f:
    writer = csv.writer(f, delimiter=',', lineterminator='\n')
    writer.writerows(data)   

以上是关于python 比较美国和印度Netflix系列| Excel文件:https://goo.gl/JZMb3C的主要内容,如果未能解决你的问题,请参考以下文章