简体   繁体   English

我可以在目标页面上解析HTML并跳转到其中的链接吗?

[英]Can I parse HTML at a target page and jump to a link inside it instead?

The short version of my question is whether code can be written so that, instead of opening a page, it parses that page and opens a link on it instead? 我的问题的简短版本是:是否可以编写代码,以便代替打开页面,它可以解析该页面并在其上打开链接? I've read a little bit about using PHP or Perl or other tools to parse HTML; 我已经读过一些有关使用PHP或Perl或其他工具来解析HTML的知识。 is this something that could be done with tools like that? 用这样的工具可以做到吗?

I maintain some pages that include links to a fixed list of language-specific documents. 我维护一些页面,其中包含指向特定于语言的文档的固定列表的链接。 The format is consistent along the lines of this (in generic fashion) with the line commented out if that document is not yet posted: 如果尚未发布该文档,则格式与此(以通用方式)一致,并注释掉该行:

<ul>
    <li><a href="(en_US link)">English</a></li>
    <!-- <li><a href="(bg_BG link)">Bulgarian</a></li> --> 
    <!-- <li><a href="(zh_CN link)">Chinese - Simplified</a></li> --> 
    <li><a href="(zn_TW link)">Chinese - Traditional</a></li> 
    ... etc.
</ul>

Someone else has links to these pages. 其他人具有这些页面的链接。

Given one of these and knowing the language desired, could they find that link in the page and jump to it instead if that line is not commented out? 给定其中之一并知道所需的语言,如果未注释掉该行,他们是否可以在页面中找到该链接并跳转到该链接? Writing a regex would be easy because these embedded URLs all end with xx_XX.pdf using whatever the language/locale is. 编写正则表达式很容易,因为无论使用xx_XX.pdf语言/区域设置,这些嵌入的URL都以xx_XX.pdf结尾。

I'm not trying to figure out what the code would be, just whether that's something one could write if they have the right tools and right knowledge. 我并不是要弄清楚代码是什么,只是如果他们拥有正确的工具和正确的知识,那是否可以写出来。

You don't give very much detail, but yes, it sounds like this is possible 您没有提供太多细节,但是是的,听起来这是可能的

Traditionally, PHP is a server-side language while Perl is more often used on the client side. 传统上,PHP是一种服务器端语言,而Perl更常在客户端使用。 It would be a bad idea to implement this on a web server system, but if you are thinking of an HTTP client then it is feasible in pretty much any language 在Web服务器系统上实现此方法不是一个好主意,但是如果您正在考虑使用HTTP 客户端,那么几乎在任何语言中都是可行的

If you don't understand the distinction between client and server then please ask 如果您不了解客户端服务器之间的区别,请询问

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

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