请教一下python大神

唐僧 · 乔 2019-07-28 10:07:04
C:/Program Files/JetBrains/PyCharm Community Edition 2019.1.3/helpers/pydev/_pydev_imps/pachong.py:22: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 22 of the file C:/Program Files/JetBrains/PyCharm Community Edition 2019.1.3/helpers/pydev/_pydev_imps/pachong.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.

soup = BeautifulSoup(html)



上面这是什么意思啊?该如何处理啊?

下面是网上找的代码

#!/usr/bin/python
# coding:utf-8

import requests
from bs4 import BeautifulSoup

test_url = 'http://movie.douban.com/top250/'


def download_page(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'
}
data = requests.get(url, headers=headers).content
return data


movie_name_list = []


def parse_html(html):
soup = BeautifulSoup(html)
movie_list_soup = soup.find('ol', attrs={'class': 'grid_view'})
if movie_list_soup != None:
for movie_li in movie_list_soup.find_all('li'):
detail = movie_li.find('div', attrs={'class': 'hd'})
movie_name = detail.find('span', attrs={'class': 'title'}).getText()
movie_name_list.append(movie_name)

next_page = soup.find('span', attrs={'class': 'next'}).find('a')
if next_page:
parse_html(download_page(test_url + next_page['href']))
return movie_name_list


def main():
handle = parse_html(download_page(test_url))
if handle != None:
handle = list(handle)
for ele in handle:
print
ele


if __name__ == '__main__':
main()
...全文
39 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

61,124

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧