设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 18484|回复: 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()

回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

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, 2024-11-24 05:40 , Processed in 0.014147 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部