【php – 解析html页面】教程文章相关的互联网学习教程文章

使用带有Javascript的Xpath解析HTML

在.NET中,有一个可爱的库,它使我可以使用xpath查询(HTML Agility Project)轻松解析外部html页面-问题是我必须在客户端执行此操作,因此只能使用javascript.有什么办法吗?解决方法:jQuery还支持xPath选择器以及CSS,您可以从下面的链接中获取更多信息. http://docs.jquery.com/DOM/Traversing/Selectors

javascript-使用documentFragment解析HTML而不发送HTTP请求【代码】

我想解析一个字符串,并用它来制作DOM树.我决定使用documentFragment API,到目前为止,我已经这样做了:var htmlString ="Some really really complicated html string that only can be parsed by a real browser!"; var fragment = document.createDocumentFragment('div'); var tempDiv = document.createElement('div'); fragment.appendChild(tempDiv); tempDiv.innerHTML = htmlString; console.log(tempDiv);但是问题是该脚本...

如何在GWT测试用例中强制HtmlUnit解析UTF-8中的Javascript文件?【代码】

我正在GWT模块上编写GWTTestCase,其中包括一个外部Javascript文件,该文件在变量名称(d3.js)中包含非ASCII字符. 我收到此错误:SEVERE: error: message=[illegal character] sourceName=[http://d3js.org/d3.v3.js] line=[2098] lineSource=[ var ??00, ?00, ??0, cos?0, sin?0;] lineOffset=[10]这是2098行的代码行:var λ00, φ00, λ0, cosφ0, sinφ0;根据HtmlUnit,这些字符(λ和φ)是有效的Javascript标识符字符(请参见the...

使用Java 6和Jsoup 1.7.3,如何在同级文本不在元素内的情况下解析此HTML?【代码】

主要是我的问题是如何解析…<p>some text<br /> <br /> <strong>categorized: </strong>like this<br /> <br /></p>…我最终对使用Java和Jsoup获得“分类”,“像这样”这样的键值对感兴趣吗?我正在查看< strong>标签是一种我可以用来指示键的定界符,然后它后面的文本(不方便地不包含在标签中)需要我抓取作为值. 我认为对我来说挑战是“像这样”的部分不在一个元素中.它是一个同级节点,但是无法通过CSS选择,因此我无法通过Jsoup找到...

如何使用PHP将bash颜色代码解析为html【代码】

我正在尝试从日志中解析行并输出html,并希望颜色代码能够正常工作. 我在网上发现了该类,该类应该起作用,但它不会使任何颜色变色,也不会删除控制代码.它应该用等效的html替换控制代码,但完全忽略它的输出[0;35;22m/plugins: [0;37;1mGets a list of plugins running on the server[m这是班<?phpfunction bashColortoHtml($string) {$ret = false;if(!empty($string)) {$_colorPattern = array('/\\033\[1;33m(.*?)\\033\[0m/s','/\\...

javascript-使用htmlparser2将html字符串解析为json【代码】

我正在尝试使用htmlparser2(https://www.npmjs.com/package/htmlparser2)将html原始字符串解析为json. 但是它的用法仅注销标签/文本,我想要的是像livedemo(http://demos.forbeslindesay.co.uk/htmlparser2/)这样的json,以便我可以过滤所需的元素. 任何帮助或建议,将不胜感激!解决方法:看了一下源代码,似乎有一个可以解决问题的辅助方法parseDOM:var htmlparser = require("htmlparser2"); elements = htmlparser.parseDOM(htmlSt...

用Python解析HTML-有些页面可以工作,有些不能…?【代码】

使用以下脚本:from lxml import html import requestsgameUrl = 'http://store.401games.ca/catalog/2415520/caylus' page = requests.get(gameUrl) tree = html.fromstring(page.content)stock = tree.xpath('//*[@id="stock"]/span[1]/div/*/text()')[0]print stock它将正确显示页面上列出的库存水平. (目前为1个)gameUrl = 'http://store.401games.ca/catalog/2415324/ticket-to-ride'它显示库存为68,这是不正确的. (我不知道6...

python-找不到具有您要求的功能的树生成器:html.parser.您需要安装解析器库吗?【代码】

我正在为AWS上的lambda开发一些代码.# import libraries import urllib.request as urllib2 from Packages.bs4 import BeautifulSoup import time import Packages.requests as requests import jsondef run(event, context):try:# specify the urlquote_page = 'http://money.cnn.com/data/hotstocks/index.html';page = urllib2.urlopen(quote_page)soup = BeautifulSoup(page, 'html.parser')tickers = soup.find_all('a', attr...

php-preg_replace仅外部标签? (…我们不是在说完整的“ html解析”,只是降价了一点)【代码】

在OCCASIONAL标记“< ...>”内的某些文本(不包括文本)加亮的最简单方法是什么? 澄清:我希望保留现有标签!$t = preg_replace("/(markdown)/","<strong>$1</strong>", "This is essentially plain text apart from a few html tags generated with some simplified markdown rules: <a href=markdown.html>[see here]</a>");应显示为: “这基本上是纯文本,除了一些用某些简化的降价规则生成的html标签:see here” …但不要在锚...

HTML解析C#【代码】

我正在解析HTML文件,并且遇到了一些问题. 我正在使用以下代码: 编辑******************************** 更新的代码现在可以使用了. 私有void PhoneApplicationPage_Loaded(对象发送者,RoutedEventArgs e) {WebClient client = new WebClient();client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);client.DownloadStringAsync(new Uri(@"http://www.SourceURL.com...

如何使用PHP Simple HTML DOM解析器对此进行解析?【代码】

这是我需要解析为PHP程序的HTML的示例:<div id="dump-list"> <div class="dump-row"> <div class="dump-location odd" data-jmapping="{id: 35, point: {lng: -73.00898601, lat: 41.71727402}, category: 'office'}"><div class="SingleLinkNoTx"><a href="#10" class="loc-link">Acme Software</a><br/><strong>John Doe, MBA</strong><br/>123 Main St.<br />New York, NY 10036<br /><strong class="telephone">(212) 555...

使用PHP解析html并遍历表行和列?【代码】

我正在尝试从loadHTML解析HTML,但是遇到了麻烦,我设法遍历了文档中的所有< tr&gt ;,但是我不知道如何遍历< td>每行. 这是我到目前为止所做的:$DOM->loadHTML($url); $rows= $DOM->getElementsByTagName('tr');for ($i = 0; $i < $rows->length; $i++) { // loop through rows// loop through columns... }我如何遍历每一行中的列?解决方法:DOMElement还支持getElementsByTagName:$DOM = new DOMDocument(); $DOM->loadHTMLFile(...

在PHP中从XML内部解析HTML标签【代码】

我正在尝试在PHP中解析http://uk.news.yahoo.com/rss时,使用simplexml_load_string创建自己的RSS feed(出于学习目的).我被困在阅读< description>内的HTML标签.标签. 到目前为止,我的代码如下所示:$feed = file_get_contents('http://uk.news.yahoo.com/rss'); $rss = simplexml_load_string($feed);//for each element in the feed foreach ($rss->channel->item as $item) {echo '<h3>'. $item->title . '</h3>'; foreach($item...

PHP简单HTML DOM解析器-RSS中的链接元素【代码】

我刚刚开始使用PHP简单HTML DOM解析器(http://simplehtmldom.sourceforge.net/),但在解析XML时遇到了一些问题. 我可以完美地解析HTML文档中的所有链接,但是无法解析RSS feed(XML格式)中的链接.例如,我想解析来自http://www.bing.com/search?q=ipod&count=50&first=0&format=rss的所有链接,因此我使用以下代码:$content = file_get_html('http://www.bing.com/search?q=ipod&count=50&first=0&format=rss');foreach($content->find...

python使用lxml和xpath解析html表上的特定数据【代码】

首先,我是python和Stack Overflow的新手,所以请客气. 这是我要从中提取数据的html页面的源代码. 网页:http://gbgfotboll.se/information/?scr=table&ftid=51168表格在页面底部<html>table class="clCommonGrid" cellspacing="0"><thead><tr><td colspan="3">Kommande matcher</td></tr><tr><th style="width:1%;">Tid</th><th style="width:69%;">Match</th><th style="width:30%;">Arena</th></tr></thead><tbody class="clGrid"...