【发布时间】:2021-11-18 15:31:44
【问题描述】:
我创建了一个蜘蛛来收集 scratch.mit.edu 上的用户名。 它成功导航到配置文件页面,但它不运行回调函数。我认为这可能与我编写允许属性的方式有关。
我的代码:
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
class ForumnSpider(CrawlSpider):
name = 'forumn'
allowed_domains = ['scratch.mit.edu']
start_urls = [
'https://scratch.mit.edu/users/accountcraft123/'
]
rules = (
Rule(
LinkExtractor(),
),
Rule(
LinkExtractor(
allow=('/users/'),
),
callback='parse_item',
),
)
def parse_item(self, response):
self.logger.info('This is a profile page. %s', response.url)
response.xpath('//div[@class="header-text"]/h2/text()').get()
【问题讨论】:
标签: python scrapy web-crawler