小编Mic*_*nez的帖子

Python Xpath:lxml.etree.XPathEvalError:谓词无效

我正在尝试学习如何抓取网页,在教程中我使用下面的代码是抛出这个错误:

lxml.etree.XPathEvalError: Invalid predicate
Run Code Online (Sandbox Code Playgroud)

我要查询的网站是(不要评判我,这是培训视频中使用的那个:/):https://itunes.apple.com/us/app/candy-crush-saga/id553834731

导致错误的xpath字符串在这里:

links = tree.xpath('//div[@class="center-stack"//*/a[@class="name"]/@href')
Run Code Online (Sandbox Code Playgroud)

我正在使用LXML并请求库.

如果您需要任何其他信息,我很乐意提供!

python xpath web-scraping python-requests lxml.html

4
推荐指数
1
解决办法
9742
查看次数

测试 Angular 组件中名为 subscribe 的方法

如果我在组件中有以下删除方法

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css']
})
export class HeroesComponent {
  this.heroes = [];

  constructor(private heroService: HeroService) { }

  delete(hero: Hero): void {
    this.heroes = this.heroes.filter(h => h !== hero);
    this.heroService.deleteHero(hero).subscribe();
  }
}
Run Code Online (Sandbox Code Playgroud)

我如何在 Jasmine 中测试删除英雄方法在测试中调用了订阅。

这是一个测试,确保使用特定参数调用 deleteHero,但我不确定如何检查订阅。

// Interaction Test
it('should call deleteHero with the specificed argument', () => {
  // arrange
  mockHeroService.deleteHero.and.returnValue(of(true));
  component.heroes = HEROES;

  // act
  component.delete(HEROES[2]);

  // assert
  expect(mockHeroService.deleteHero).toHaveBeenCalledWith(HEROES[2]);
});
Run Code Online (Sandbox Code Playgroud)

jasmine rxjs angular

0
推荐指数
1
解决办法
832
查看次数