简体   繁体   English

识别网站页面上的某个公共部分

[英]Identifying a certain common section on pages in a website

I have a list of common links for product pages, and I need to go through and grab all the links for the product image on each product page. 我有一个产品页面的常用链接列表,我需要仔细阅读每个产品页面上产品图像的所有链接。

Eg I have got this far: I have a whole spreadsheet full of links like this 例如,我已经了解到了这一点:我有一个完整的电子表格,其中包含这样的链接

http://www.apc.com/products/moreimages.cfm?partnum=WSYSW100KF

the problem is I need the acutal image links for another column on my spreadsheet (it;s going to be used for a import on a eccomerce shop) 问题是我需要电子表格上另一列的原始图像链接(它将用于eccomerce商店中的导入)

the thing is these image links don't seem to match up in any way and can be quite varied 问题是这些图像链接似乎没有任何匹配,并且可以变化很多

http://www.apcmedia.com/resource/images/500/Front_Left/98EC66CA-5056-AE36-FE51936B432B1C17_pr.jpg

I have identified though that these images sit in what looks like a common area on the product page code 我已经确定这些图像位于产品页面代码中看起来像是公共区域的位置

<div align="center"><img align="center" src="http://www.apcmedia.com/resource/images/500/Front_Left/98EC66CA-5056-AE36-FE51936B432B1C17_pr.jpg"></div>

How can I indetify that <img align="center" src=""> part in Jquery on each page ? 如何在每页的Jquery中确定<img align="center" src="">部分?

I'm thinking if I iterate through all those links, then I can grab the releavnt direct Image link, grab it and repopulate into another spreadsheet column. 我在考虑是否要遍历所有这些链接,那么我可以抓住重新释放的“直接图像”链接,抓住它,然后重新填充到另一个电子表格栏中。

I'm just not 100% on how to achieve this, any advice would be greatly appreciated. 我不是100%如何做到这一点,任何建议将不胜感激。

Thanks 谢谢

Use this selector to select the relevant images: 使用此选择器选择相关图像:

var result = [];
$("div[align=center] > img[align=center]").each(function(){
   var link = $(this).prop("src");
   //Do something, eg:
   result.push(link);
});
//result is a list which hold all links

.prop() returns the absolute URL of an image, even when the src attribute contains a relative URL. .prop()返回图像的绝对URL,即使src属性包含相对URL。
A > B selects every element B which is an immediate child of A . A > B选择作为A的直接子元素的每个元素B

If your src attribute * follows a certain pattern, you can also use the following selector: 如果您的src 属性 *遵循某种模式,则还可以使用以下选择器:

$("div[align=center] > img[src^='http://path/to/images'][src$='.jpg']");
//src^= means: Match if the `src` attribute starts with ...
//src$= means: Match if the `src` attribute ends with ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM