One little question ( import)

37 переглядів
Перейти до першого непрочитаного повідомлення

field....@gmail.com

не прочитано,
5 січ. 2017 р., 04:26:5005.01.17
Кому: scrapy-users
Hey, everyone. I'm new to scrapy and there are things I do not understand. 
The question I have is this.
When I create a spider how to figure out what to import? Maybe I'm a Python really do not know, do not argue.
For example.
rules = (
Rule(LinkExtractor(allow=(r"href=\"\/courses\/\d*\"", )), callback='parse'),
)
Doesn't work for me, if I don't do from scrapy.contrib.spiders import CrawlSpider, Rule
Here's how I understand what and when to import? 
Thank you.

Paul Tremberth

не прочитано,
5 січ. 2017 р., 04:53:0005.01.17
Кому: scrapy-users
Hi there,
welcome to the scapy community!

The online documentation has lots of code snippets with valid import statements.

which shows these imports:

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

You also have the Index (https://docs.scrapy.org/en/latest/genindex.html) to go to the different classes and methods.
(Most classes are documented on https://docs.scrapy.org and listed in the index)

I was about to take LinkExtractor as an example, but in fact it's an alias for
scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor


Let's take Rule as example.
In the index, you can find it on https://docs.scrapy.org/en/latest/genindex.html#R
and you can see
classscrapy.spiders.Rule(link_extractor, callback=None, cb_kwargs=None, follow=None, process_links=None, process_request=None)

So to use the Rule class and instances in your code, you'll have to import something like this:

from scrapy.spiders import Rule


Hope this helps.

/Paul.

field....@gmail.com

не прочитано,
6 січ. 2017 р., 04:21:1206.01.17
Кому: scrapy-users
Paul, thank you very much. I figured out how to import all thanks to you. You answer is so painted that the questions and left. Thanks again.
Відповісти всім
Відповісти автору
Переслати
0 нових повідомлень