请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站

Crossin的编程教室

微信公众号:
crossincode
 找回密码
 立即加入
查看: 48|回复: 1

请大佬们看看是哪里错了,想破头想不出呜呜

[复制链接]

1

主题

0

好友

5

积分

新手上路

Rank: 1

发表于 2020-10-14 10:51:46 |显示全部楼层
#-*- coding:utf-8 -*-
import re
from bs4 import BeautifulSoup
import xlwt
import sqlite3
import urllib.request,urllib.error
import urllib.parse



def main():
    gethtml(url = "https://movie.douban.com/top250?start=0")
    getdata(baseurl = "https://movie.douban.com/top250?start=0")


# def find_thing():



def gethtml(url):
    html = ""
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
    }
    req = urllib.request.Request(url, headers=headers)
    response = urllib.request.urlopen(req)
    print(response.read().decode("utf-8"))
    # return html


def getdata(baseurl):
    datalist = []
    for i in range(0,1):
        url = baseurl + str(i*25)
        html = gethtml(url)

        soup = BeautifulSoup(html,"html.parser")
        for item in soup.find_all('div',class_ ="item"):
            datalist.append(item)






if __name__ == '__main__':
    main()








Traceback (most recent call last):
  File "C:/Users/11929/PycharmProjects/untitled1/htmlfirst.py", line 47, in <module>
    main()
  File "C:/Users/11929/PycharmProjects/untitled1/htmlfirst.py", line 13, in main
    getdata(baseurl = "https://movie.douban.com/top250?start=0")
  File "C:/Users/11929/PycharmProjects/untitled1/htmlfirst.py", line 37, in getdata
    soup = BeautifulSoup(html,"html.parser")
  File "C:\Users\11929\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__init__.py", line 310, in __init__
    elif len(markup) <= 256 and (
TypeError: object of type 'NoneType' has no len()

回复

使用道具 举报

158

主题

37

好友

8万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2020-10-14 16:38:22 |显示全部楼层
html = gethtml(url)

gethtml没有返回值,所以html是None
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|Archiver|手机版|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2020-10-25 00:55 , Processed in 0.049713 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部