如何在 Chrome 中获取 CSS 选择器?

发布于 2024-10-08 07:45:44 字数 426 浏览 0 评论 0原文

我希望能够选择/突出显示页面上的元素并找到其选择器,如下所示:

div.firstRow div.priceAvail>div>div.PriceCompare>div.BodyS

我知道您可以在执行检查元素后看到底部的选择,但如何将此路径复制到剪贴板?在 Firebug 中,我认为您可以做到这一点,但没有找到使用 Chrome 开发人员工具执行此操作的方法,并且搜索扩展程序没有找到任何内容。

这就是我试图做的,以供更多参考: http://asciicasts.com/episodes/173-screen-scraping-with-scrapi

I want to be able to select/highlight an element on the page and find its selector like this:

div.firstRow
div.priceAvail>div>div.PriceCompare>div.BodyS

I know you can see the selection on the bottom after doing an inspect element, but how can I copy this path to the clipboard? In Firebug I think you can do this, but don't see a way to do this using the Chrome Developer Tools and search for an extension did not turn-up anything.

This is what I am trying to do for more reference:
http://asciicasts.com/episodes/173-screen-scraping-with-scrapi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风尘浪孓 2024-10-15 07:45:44

Chrome Dev Tools CSS Path

如果 Chrome Dev Tools 在源窗格中选择该元素并右键单击,那么您将看到“复制 CSS 路径”选项。

在较新版本的 Chrome 中,这是 (右键单击)>复制>复制选择器
您还可以通过 (右键单击)> 获取 XPath复制>复制 XPath

Chrome Dev Tools CSS Path

If Chrome Dev tools if you select the element in the source pane and right click, then you will see the "Copy CSS Path" option.

In newer versions of Chrome, this is (right-click) > Copy > Copy selector.
You can also get the XPath with (right-click) > Copy > Copy XPath

予囚 2024-10-15 07:45:44

虽然不是扩展,但我确实找到了一个名为 Selector Gadget 的书签,它正是我正在寻找的东西。

Although not an extension, I did find a bookmarklet called Selector Gadget that does exactly what I was looking for.

尐籹人 2024-10-15 07:45:44

我目前从最新 Chrome 版本 (59) 的元素获取 CSS 选择器的工作流程如下:

  1. 打开 Chrome 开发工具 (cmd/ctrl + alt + j):

第 1 步 - 打开 Chrome 开发工具

  1. 点击页面中的选择元素工具(cmd/ctrl + alt + c):

第 2 步 - 单击页面中的选择元素工具

  1. 单击您想要的元素获取选择器以便在开发工具面板中查看它:

第 3 步 - 选择元素

  1. 右键单击​​开发工具元素:

第 4 步 - 右键单击​​元素

  1. 单击复制 ->复制选择器:

第 5 步 - 复​​制选择器

这给了我以下内容:

#question >表>正文> tr:第 n 个子级(1) > td.postcell>分区> div.post-text>块引用>

The workflow I currently follow to get CSS selectors from elements with the latest Chrome version (59) is as follows:

  1. Open Chrome Dev tools (cmd/ctrl + alt + j):

Step 1 - Opening Chrome Dev tools

  1. Click on the select element tool in page (cmd/ctrl + alt + c):

Step 2 - Clicking on the select element tool in page

  1. Click on the element you want to get the selector from in order to view it in the dev tools panel:

Step 3 - Selecting the element

  1. Right click on the dev tools element:

Step 4 - Right clicking on the element

  1. Click on Copy -> Copy selector:

Step 5 - Copy selector

Which gives me the following:

#question > table > tbody > tr:nth-child(1) > td.postcell > div > div.post-text > blockquote > p

等风来 2024-10-15 07:45:44

执行“检查元素”或Ctrl+Shift+I,它位于屏幕的最底部。如果不确定选择器,您还可以在开发工具右上角的“搜索元素”框中键入。

Do "Inspect Element" or Ctrl+Shift+I, it's at the VERY bottom of the screen. You can also type in the "Search Elements" box at the top-right of the dev tools if not sure about the selector.

手心的温暖 2024-10-15 07:45:44

如果您继承了一个非常复杂的应用程序结构,并且试图追踪一个非常棘手的多重嵌套 CSS 深度问题,有时有必要执行此操作。 Jquery mobile pre 1.3 就是一个很好的例子。引导应用程序等。

我尝试了上述工具,但无法真正选择类似于原始海报问题的复杂继承的整个父级和子级。

It's sometime necessary to do this if you have a very complex app structure that you inherited and are trying to track down a very tricky multi nested css depth problem. Jquery mobile pre 1.3 would be a good example of this. Bootstrap apps etc..

I tried the above tool but could not get that to actually select the entire parent and children of a complex inheritance similar to the original posters question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文