破壳不开龙麟

2024-05-23 15:09:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我在处理 皮屑。我尝试爬网的URL是:http://allegro.pl/sportowe-uzywane-251188?a_enum[127779][15]=15&a_text_i[1][0]=2004&a_text_i[1][1]=2009&a_text_i[5][0]=950&id=251188&offerTypeBuyNow=1&order=p&string=gsxr&bmatch=base-relevance-aut-1-5-0913

但当我做“查看(回应)”时,我得到的是空白页 页面似乎未加载

>>> response.css("title")
[]

有趣的是,有时它可以用相同的命令集正确地加载


Tags: textidhttpurlstringallegroorderenum
2条回答

非常感谢mertyildiran的帮助。在

皮屑对我不管用。有时它能上网,但大多数时候不上网。我不知道为什么。在

不管怎样,我最终得到的代码每次都很好。在

进口废料

类引号(痒。蜘蛛): name=“快板” 起始URL=['http://allegro.pl/sportowe-uzywane-251188?a_enum%5B127779%5D%5B15%5D=15&a_text_i%5B1%5D%5B0%5D=2004&a_text_i%5B1%5D%5B1%5D=2009&a_text_i%5B5%5D%5B0%5D=950&id=251188&offerTypeBuyNow=1&order=p&string=gsxr&bmatch=base-relevance-aut-1-1-0913']

def parse(self, response):
    for lista in response.css("article.offer"):
        yield {
        'link': lista.css('a.offer-title::attr(href)').extract(),            
        }

这对我很有用,我建议你从最基本的教程开始:

import scrapy

class BlogSpider(scrapy.Spider):
    name = 'blogspider'
    start_urls = ['http://allegro.pl/sportowe-uzywane-251188?a_enum%5B127779%5D%5B15%5D=15&a_text_i%5B1%5D%5B0%5D=2004&a_text_i%5B1%5D%5B1%5D=2009&a_text_i%5B5%5D%5B0%5D=950&id=251188&offerTypeBuyNow=1&order=p&string=gsxr&bmatch=base-relevance-aut-1-1-0913']

    def parse(self, response):
        print "                                "
        print response.body
        print "                                "

我可以看到页面的正文。view(response)错误,未定义函数。在

将此代码另存为myspider.py,并使用scrapy runspider myspider.py运行。您将看到一个大字符串打印到您的终端中,即 -s之间的主体

对于破壳:

以shell模式启动:scrapy shell

只需运行:

^{pr2}$

它将在您的默认浏览器中打开刮掉的页面。你的网址对我有用。在

对于标题标签,它显示:

^{3}$

已爬网/刮取的网页将保存在/tmp目录下,类似于/tmp/tmpn8wziQ.html

相关问题 更多 >