本文整理汇总了Python中scrapy.FormRequest.meta["first_url"]方法的典型用法代码示例。如果您正苦于以下问题:Python FormRequest.meta["first_url"]方法的具体用法?Python FormRequest.meta["first_url"]怎么用?Python FormRequest.meta["first_url"]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.FormRequest
的用法示例。
在下文中一共展示了FormRequest.meta["first_url"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from scrapy import FormRequest [as 别名]
# 或者: from scrapy.FormRequest import meta["first_url"] [as 别名]
def parse(self, response):
url = response.url
if "research" in url:
categories = response.xpath(".//*[@class='catec']")
for i in xrange(len(categories)-1):
large_categories = categories[i].xpath(".//*[@class='fl']")
large_category_name = clean_text(large_categories.xpath(".//text()").extract()[0].strip())
mid_categories = categories[i].xpath(".//span")
for mid_category in mid_categories:
mid_category_name = clean_text(mid_category.xpath(".//text()").extract()[0].strip())
page_url = mid_category.xpath(".//@href").extract()[0]
request = FormRequest(page_url, callback=self._parse_page_research, dont_filter=True)
request.meta["large_category"] = large_category_name
request.meta["mid_category"] = mid_category_name
request.meta["first_url"] = page_url
yield request
elif "free" in url:
large_categories = response.xpath(".//*[@class='tul2']//h2//a")
for i in xrange(len(large_categories)):
large_category_name = clean_text(large_categories[i].xpath(".//text()").extract()[0].strip())
page_url = large_categories[i].xpath("./@href").extract()[0]
request = FormRequest(page_url, callback=self._parse_page_free, dont_filter=True)
request.meta["large_category"] = large_category_name
request.meta["first_url"] = page_url
yield request
示例2: parse_middle_category
# 需要导入模块: from scrapy import FormRequest [as 别名]
# 或者: from scrapy.FormRequest import meta["first_url"] [as 别名]
def parse_middle_category(self, response):
mid_categories = response.xpath(".//*[@class='report2']//h2//a")
for mid_category in mid_categories:
mid_category_name = clean_text(mid_category.xpath("./text()").extract()[0].strip())
page_url = mid_category.xpath("./@href").extract()[0]
url = urljoin(self.base_url, page_url)
request = FormRequest(url, callback=self._parse_item, dont_filter=True)
request.meta["large_category"] = response.meta["large_category"]
request.meta["mid_category"] = mid_category_name
request.meta["first_url"] = url
yield request