我在建一个爬行蜘蛛从以下网站(https://www.azleg.gov/viewdocument/?docName=https://www.azleg.gov/ars/1/00101.htm)中搜集成文法数据。我的目标是提取法规文本,它包含在以下XPath[/div[@class='first']/p/text()]中。该路径应提供法规文本。你知道吗
我的所有scrapy请求都会产生不完整的html响应,因此当我搜索相关的xpath查询时,它会产生一个空列表。但是,当我使用请求库时,html会正确下载。你知道吗
使用XPathTesterOnline,我已经验证了我的XPath查询应该产生所需的内容。使用ScrapyShell,我在浏览器中查看了scrapy的响应对象—它看起来就像我本机浏览时一样。我尝试过为BeautifulSoup和Selenium启用中间件,但似乎都不起作用。你知道吗
这是我的爬行蜘蛛class AZspider(CrawlSpider):
name = "arizona"
start_urls = [
"https://www.azleg.gov/viewdocument/?docName=https://www.azleg.gov/ars/1/00101.htm",
]
rule = (Rule(LinkExtractor(restrict_xpaths="//div[@class = 'article']"), callback="parse_stats_az", follow=True),)
def parse_stats_az(self, response):
statutes = response.xpath("//div[@class = 'first']/p")
yield{
"statutes":statutes
}
下面是成功生成正确响应对象的代码az_leg = requests.get("https://www.azleg.gov/viewdocument/?docName=https://www.azleg.gov/ars/1/00101.htm")