| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1979 人关注过本帖
标题:请求各位大神,出现'NoneType' object has no attribute 'content'该怎么解 ...
只看楼主 加入收藏
littlemark
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-3-10
收藏
 问题点数:0 回复次数:0 
请求各位大神,出现'NoneType' object has no attribute 'content'该怎么解决?
import urllib.request
from bs4 import BeautifulSoup

def get_page(url):
    kv = {'User-Agent': 'Mozilla/5.0', 'Cookie':'BAIDUID=0156185E725928F549DB48FE0A1DDE69:FG=1; PSTM=1551762939; BIDUPSID=63EAE36946BA95A4145B1A726A4422A2; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; CPROID=0156185E725928F549DB48FE0A1DDE69:FG=1; locale=zh; delPer=0; H_PS_PSSID=1432_21111_28608_28584_28557_28518_28625_28606; PSINO=7; ISBID=0156185E725928F549DB48FE0A1DDE69:FG=1; ISUS=0156185E725928F549DB48FE0A1DDE69:FG=1'}
    req = urllib.request.Request(url, headers=kv)
    response = urllib.request.urlopen(req)
    html = response.read().decode('utf-8', 'ignore')
    return html

def find_img(html):
    soup = BeautifulSoup(get_page(html), 'html.parser')
    my_girl = soup.find_all('img')
    for girl in my_girl:
        link = girl.get('src')
        return link

def save(link):
    root = "D://pics//"
    path = root + link.split('/')[-1]
    r = find_img(link)
    with open(path, 'wb') as f:
        f.write(r.content)
        f.close()

def main():
    url = 'https://www.'
    pages = 6
    for i in range(pages):
        i += 1
        page_url = url + '?pager_offset=' + str(i)
        link = find_img(page_url)
        save(link)
main()
搜索更多相关主题的帖子: url request def html link 
2019-03-10 13:11
快速回复:请求各位大神,出现'NoneType' object has no attribute 'content'该怎 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040696 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved