#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数据库内容请搜索靠谱客的其他文章。
发表评论 取消回复