会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 134307个问题
Python全系列/第十六阶段:Python 爬虫开发/爬虫反反爬- 286楼

from urllib.request import Request,build_opener,HTTPCookieProcessor
from urllib.parse import urlencode
from fake_useragent import UserAgent
from http.cookiejar import MozillaCookieJar
import ssl
def get_cookie():
    url = 'https://rl.mail.qq.com/cgi-bin/getinvestigate?sid=ucPJvMl86d29Q1wC'
    headers={
        'User-Agent':UserAgent().chrome
    }
    data = {
        'user': '523531642',
        'password': '*********'
    }
    context = ssl._create_unverified_context()
    res = Request(url,headers=headers,data=urlencode(data).encode())
    cookiejar = MozillaCookieJar()
    handler = HTTPCookieProcessor(cookiejar)
    opener = build_opener(handler)
    resp = opener.open(res)
    cookiejar.save('cookie.text',ignore_discard=True,ignore_expires=True)
def use_cookie():
    info_url='https://mail.qq.com'
    headers = {
        'User-Agent': UserAgent().chrome
    }
    context = ssl._create_unverified_context()
    res = Request(info_url, headers=headers, data=urlencode(headers).encode())
    cookiejar = MozillaCookieJar()
    cookiejar.load('cookie.text',ignore_expires=True,ignore_discard=True)
    handler = HTTPCookieProcessor(cookiejar)
    opener = build_opener(handler)
    resp = opener.open(res)
    print(resp.read())
if __name__ == '__main__':
    get_cookie()
    #use_cookie()

老师这个qq邮箱是https   我保存的的cookie文件为什么不行

是登录的url有问题吗?老师我的代码有问题吗?

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file!  Do not edit.

.mail.qq.com   TRUE   /  FALSE     qm_sk  
.mail.qq.com   TRUE   /  FALSE     qm_ssum    
.qq.com    TRUE   /  FALSE     qm_sk  
.qq.com    TRUE   /  FALSE     qm_ssum


Python全系列/第十六阶段:Python 爬虫开发/scrapy框架使用(旧) 287楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 288楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 289楼

老师:我运行代码就报错,

  

2020-03-30 15:25:37 [scrapy.utils.log] INFO: Scrapy 2.0.1 started (bot: book)

2020-03-30 15:25:37 [scrapy.utils.log] INFO: Versions: lxml 4.5.0.0, libxml2 2.9.5, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 20.3.0, Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)], pyOpenSSL 19.1.0 (OpenSSL 1.1.1d  10 Sep 2019), cryptography 2.8, Platform Windows-10-10.0.17763-SP0

2020-03-30 15:25:37 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor

2020-03-30 15:25:37 [scrapy.crawler] INFO: Overridden settings:

{'BOT_NAME': 'book',

 'NEWSPIDER_MODULE': 'book.spiders',

 'SPIDER_MODULES': ['book.spiders'],

 'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '

               '(KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}

2020-03-30 15:25:37 [scrapy.extensions.telnet] INFO: Telnet Password: 55216b70a4289d90

2020-03-30 15:25:37 [scrapy.middleware] INFO: Enabled extensions:

['scrapy.extensions.corestats.CoreStats',

 'scrapy.extensions.telnet.TelnetConsole',

 'scrapy.extensions.logstats.LogStats']

2020-03-30 15:25:37 [scrapy.middleware] INFO: Enabled downloader middlewares:

['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',

 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',

 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',

 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',

 'scrapy.downloadermiddlewares.retry.RetryMiddleware',

 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',

 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',

 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',

 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',

 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',

 'scrapy.downloadermiddlewares.stats.DownloaderStats']

2020-03-30 15:25:37 [scrapy.middleware] INFO: Enabled spider middlewares:

['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',

 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',

 'scrapy.spidermiddlewares.referer.RefererMiddleware',

 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',

 'scrapy.spidermiddlewares.depth.DepthMiddleware']

2020-03-30 15:25:37 [scrapy.middleware] INFO: Enabled item pipelines:

[]

2020-03-30 15:25:37 [scrapy.core.engine] INFO: Spider opened

2020-03-30 15:25:37 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)

2020-03-30 15:25:37 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023

2020-03-30 15:25:37 [scrapy.core.scraper] ERROR: Error downloading <GET htttp://www.zongheng.com/rank/details.html?rt=1&p=1>

Traceback (most recent call last):

  File "C:\Programs\Python\Python38\lib\site-packages\twisted\internet\defer.py", line 1416, in _inlineCallbacks

    result = result.throwExceptionIntoGenerator(g)

  File "C:\Programs\Python\Python38\lib\site-packages\twisted\python\failure.py", line 512, in throwExceptionIntoGenerator

    return g.throw(self.type, self.value, self.tb)

  File "C:\Programs\Python\Python38\lib\site-packages\scrapy\core\downloader\middleware.py", line 42, in process_request

    defer.returnValue((yield download_func(request=request, spider=spider)))

  File "C:\Programs\Python\Python38\lib\site-packages\scrapy\utils\defer.py", line 55, in mustbe_deferred

    result = f(*args, **kw)

  File "C:\Programs\Python\Python38\lib\site-packages\scrapy\core\downloader\handlers\__init__.py", line 74, in download_request

    raise NotSupported("Unsupported URL scheme '%s': %s" %

scrapy.exceptions.NotSupported: Unsupported URL scheme 'htttp': no handler available for that scheme

2020-03-30 15:25:37 [scrapy.core.engine] INFO: Closing spider (finished)

2020-03-30 15:25:37 [scrapy.statscollectors] INFO: Dumping Scrapy stats:

{'downloader/exception_count': 1,

 'downloader/exception_type_count/scrapy.exceptions.NotSupported': 1,

 'downloader/request_bytes': 323,

 'downloader/request_count': 1,

 'downloader/request_method_count/GET': 1,

 'elapsed_time_seconds': 0.324646,

 'finish_reason': 'finished',

 'finish_time': datetime.datetime(2020, 3, 30, 7, 25, 37, 768198),

 'log_count/ERROR': 1,

 'log_count/INFO': 10,

 'scheduler/dequeued': 1,

 'scheduler/dequeued/memory': 1,

 'scheduler/enqueued': 1,

 'scheduler/enqueued/memory': 1,

 'start_time': datetime.datetime(2020, 3, 30, 7, 25, 37, 443552)}

2020-03-30 15:25:37 [scrapy.core.engine] INFO: Spider closed (finished)


Python全系列/第十六阶段:Python 爬虫开发/移动端爬虫开发- 290楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础 291楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 293楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 294楼
Python全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 295楼

noval.zip

老师帮我看下,为什么我的代码同一篇文章会输出两次

Python全系列/第十六阶段:Python 爬虫开发/移动端爬虫开发- 296楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637