我有兴趣只提取 XHR 的 url,而不是网页中的每个 url:

这是我提取页面中每个网址的代码:
import scrapy
import json
from scrapy.selector import HtmlXPathSelector
from scrapy.spiders import CrawlSpider, Rule, Spider
from scrapy.linkextractors import LinkExtractor
class test(CrawlSpider):
name = 'test'
start_urls = ['SomeURL']
filename = 'test.txt'
rules = (
Rule(LinkExtractor(allow=('', )) ,callback='parse_item'),
)
def parse_item(self, response):
# hxs = HtmlXPathSelector(response)
with open ('test.txt', 'a') as f:
f.write (response.url + '\n' )
Run Code Online (Sandbox Code Playgroud)
谢谢,
编辑:您好,感谢您的评论。经过更多研究后,我发现了这个:Scraping ajax Pages using python 我想要的是自动完成这个答案。我需要对大量网页执行此操作,并且手动插入网址不是一个选项。有没有办法做到这一点?监听站点的 XHR 请求并保存 url?