我是靠谱客的博主 傻傻日记本,这篇文章主要介绍猫眼电影票房爬取到MySQL中_猫眼电影爬取(二):requests+beautifulsoup,并将数据存储到mysql数据库...,现在分享给大家,希望可以做个参考。

#coding: utf-8#author: hmk

importrequestsfrom bs4 importBeautifulSoup

import bs4importpymysql.cursorsdefget_html(url, header):try:

r= requests.get(url=url, headers=header, timeout=20)

r.encoding=r.apparent_encodingif r.status_code == 200:returnr.textelse:returnNoneexcept:returnNonedefget_data(html, list_data):

soup= BeautifulSoup(html, 'html.parser')

dd= soup.find_all('dd')for t indd:

if isinstance(t, bs4.element.Tag): # 判断t是否为bs4的tag对象(因为解析出的dd标签中可能有空行)

ranking= t.i.string #排名

movie = t.find('p', class_='name').string

release_time= t.find('p', class_='releasetime').string

score= t.find('p', class_='score').contents[0].string + t.find('p', class_='score').contents[1].string

list_data.append([rank

最后

以上就是傻傻日记本最近收集整理的关于猫眼电影票房爬取到MySQL中_猫眼电影爬取(二):requests+beautifulsoup,并将数据存储到mysql数据库...的全部内容,更多相关猫眼电影票房爬取到MySQL中_猫眼电影爬取(二):requests+beautifulsoup,并将数据存储到mysql数据库内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部