木偶从带有alt属性的html获取img

时间:2020-07-08 20:31:55

标签: javascript html node.js puppeteer

emailSignUp(email: string, password: string) { return this.afAuth.auth .createUserWithEmailAndPassword(email, password) .then(credential => { // ------------- update profile ------------- // credential.user.updateProfile({ displayName: "exampleName", photoUrl: "https://photo..." }) // ------------------------------------------ // this.pushUserData(credential.user); console.log('Usuario creado') this.router.navigate(['/login']) }) .catch(error => { this.handleError(error) }); } If you do not want to add an User doc to Firestore and just use the Firestore Auth data, you don`t need the pushUserData() method.

我有以下html。

通过操纵up,如何获得产品图片2的图片来源(来源= alt =值)

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center"><!-- Start Product Photo --><div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1"><br><img src="/products/ca/downloads/images/54631_WIP.jpg" alt="Product image 2"><br><p>images not to scale</p></div><!-- End Product Photo --></div>

在let图片中,如何使用dom选择器锁定alt值=产品图片2的img src?

非常感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您将要使用Attribute Selector。我相信您要查找的确切选择器是img[alt="Product image 2"]

let image = document.querySelector('img[alt="Product image 2"]').src;
console.log(image);
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center">
  <!-- Start Product Photo -->
  <div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1"><br><img src="/products/ca/downloads/images/54631_WIP.jpg" alt="Product image 2"><br>
    <p>images not to scale</p>
  </div>
  <!-- End Product Photo -->
</div>

答案 1 :(得分:0)

您可以使用 查询选择器中的img[alt=desired value] 然后使用image变量,您可以使用src

提取image.src变量