【发布时间】:2018-08-08 11:01:33
【问题描述】:
您好,我是 scrapy 的新手,我想从 html 元素中提取属性值。那么从 html 中提取该属性值的正确方法是什么?我想提取“data-next-url”属性
<div class="loading_more_jobs" data-type="loading_more_jobs" style="display:none;" data-next-url="https://www.ziprecruiter.com/candidate/search?search=restaurant&page=2&location=Atlanta%2C+Georgia"></div>
我正在使用那个 xpath,但它不工作
response.xpath('//*[@class="loading_more_jobs"]/@data-next-url').extract()
【问题讨论】:
-
在浏览器中禁用 JS,然后查看源代码中是否存在该元素,我确定它不存在,您的 Xpath 看起来还不错
-
那么如果我想获得那个属性值该怎么办
-
如果它不在源代码中,您必须研究该网站如何通过 AJAX 加载该数据,或者他们已经在页面上以 JSON 或其他形式提供该数据。
-
ziprecruiter.com/candidate/… 我想从该页面的“加载更多工作”中获取该信息
标签: python xpath web-scraping scrapy css-selectors