问题标签 [phpquery]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5021 浏览

php - 用于 PHP 的抓取库 - phpQuery?

我正在寻找一个 PHP 库,它允许我删除网页并处理所有 cookie 并使用默认值预填充表单,这是最让我烦恼的。

我厌倦了必须将每个输入元素与 xpath 匹配,如果存在更好的东西,我会很高兴。我遇到过phpQuery,但手册不是很清楚,我不知道如何发出 POST 请求。

有人能帮我吗?谢谢。

@乔纳森芬兰:

在 browserGet() 手册提供的示例中,我们有:

我想所有其他字段都被废弃并在 GET 请求中发回,我想对 phpQuery::browserPost() 方法做同样的事情,但我不知道该怎么做。我试图抓取的表单有一个输入令牌,如果 phpQuery 可以足够聪明地抓取令牌并让我更改其他字段(在本例中为用户名和密码),我希望通过 POST 提交所有内容。

PS:请放心,这不会用于发送垃圾邮件。

0 投票
1 回答
637 浏览

php - jQuery过滤和遍历(phpQuery)

我正在尝试使用 phpquery(几乎与 jquery 相同)从页面中解析数据,

我需要代码来获得这两件事,

BK古达会馆

Main Road, C Type Colony, BK Guda

其他的可以省略。。

这是html

0 投票
2 回答
100 浏览

php - 如何防止查询类处理我的文本字符串中的问号?

对php来说相当新,如果这看起来很愚蠢,很抱歉。我真的从我公司其他开发人员以前编写的代码中复制了很多这样的代码。

我们运行查询的方式基本上是这样的:

我遇到的问题是$textVar或者$text2Var可能合法地在其中包含问号(?)作为其文本的一部分,这导致查询 SQLQuery 类中断将问号视为我没有传递它的变量。

那么如何指示 SQLQuery 类忽略问号呢?

ps 我确定有很多我不知道的术语,请在给我答案时记住这一点。

0 投票
1 回答
1336 浏览

php - 使用 phpQuery 选择特殊的 XML 标签

phpQuery是一个非常好的工具,它在过去解析格式良好的 XHTML 和 XML 文档时帮助我很大,但我最近在尝试选择标记名中带有冒号的元素时遇到了问题,例如:

我尝试使用该pq()函数来选择所有这些元素:

不幸的是,这无济于事。如果我尝试另一个元素,例如 的标记名id,结果会按预期弹出。

0 投票
4 回答
11873 浏览

php - 使用 php 修复 html 文档上错误显示的编码

有没有办法修复通过 phpquery::newDocument 运行此 html 标记后显示不正确的字符?原始文档中的 -Classics with modern Woman- 周围有预定的双引号,在使用 phpquery 创建新文档后最终显示不正确。

原始输出:曼谷的史密斯先生庆祝“经典与现代女性”。

新文件输出:曼谷的史密斯先生与现代女性一起庆祝“经典”。

0 投票
5 回答
4017 浏览

php - 使用 phpquery 替换元素(jquery 的 php 版本)

我想用 phpquery替换所有<span>标签。<p>我的代码有什么问题?它发现span但 replaceWith 函数没有做任何事情。

本文档表明这是可能的:
http ://code.google.com/p/phpquery/wiki/Manipulation#Replaceing
http://api.jquery.com/replaceWith/

这是在代码中有和没有返回的 html ->replaceWith('<p></p>')

0 投票
2 回答
105 浏览

php - phpQuery 中的当前行号/列号?

如何获取 phpQuery 中当前元素的行号/列号?

我将 phpQuery 框架用于带有自定义错误的验证工具。

谢谢!

0 投票
3 回答
1498 浏览

jquery - 使用 phpQuery 选择特定的文本节点

好吧,这让我发疯了。我正在尝试使用 phpQuery 对以下看似微不足道的 HTML 进行屏幕抓取:

日期很简单,因为它包含在 nobr 标签中,例如。$element[':first-child']->text()成功了。 但是,如何在第二段文字上戴上脏兮兮的手套呢?

CSS 仅适用于元素,因此nth-child(2),(3)返回周围的<br>标签,而不是文本。

如果我可以 XPath 它,第二个节点.//text()将是黄金。但显然在 phpQuery-land 中,上下文$element->xpath->query('.//text()')是文档根目录,所以我得到了整个文档中的每一段文本!

想法?如何使用 jQuery 选择文本节点中的所有解决方案?似乎涉及到 Javascript DOM 操作,这比 PHP 糟糕的 DOM API 要少得多。也许只是将整个元素转储到字符串并爆炸它<br>是要走的路......

0 投票
1 回答
5467 浏览

phpquery - phpQuery 从空标签中获取 attr

我有一个让我非常恼火的问题。我正在使用 cURL 和 phpQuery 的组合从网页中获取一些内容。

在我正在获取的页面中,有以下代码确定帖子评分:

我正在使用 phpQuery 如下:

显然,评级是在<li>标签中定义的,在style属性中。我想用它来访问它,pq($li)->find('ul > li.current-rating')->attr('style')我希望得到width:0px结果。评级定义如下:0-0、12-1、24-2、...、60-6。

但是,phpQuery 似乎对空标签非常“感兴趣”。对于我从页面中获取的所有其他内容,它运行良好。

有任何想法吗?谢谢

0 投票
1 回答
3484 浏览

php - PhpQuery 是如何工作的?试图获得价值 tag</h1> <div id="body"><p>I'm new to <a href="http://code.google.com/p/phpquery/" rel="nofollow">phpQuery</a>. I need to achieve the simple task of getting the content of the HTML TITLE tag of a</a> </h3> <div class="s-post-summary--content-excerpt"> </div> <div class="s-post-summary--meta"> <div class="s-post-summary--meta-tags tags js-tags t-cñ t-ûnet t-aspûnet-mvc t-aspûnet-mvc-4 t-actionfilterattribute"> <a href="/tags/php" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">php</a><a href="/tags/tags" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">tags</a><a href="/tags/title" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">title</a><a href="/tags/phpquery" class="post-tag flex--item mt0 js-tagname-cñ" title="" rel="tag">phpquery</a> </div> <div class="s-user-card s-user-card__minimal"> <div class="s-user-card--info"> <div class="s-user-card--link d-flex gs4"> </div> </div> <time class="s-user-card--time" style="margin-left:5px;"> <span title="2022-04-18 08:34:11Z" class="relativetime"> 2011-01-04T16:18:16.847</span></time> </div> </div> </div> </div> </div> <br class="cbt"> <div class="s-pagination site1 themed pager float-left"> <a class="s-pagination--item js-pagination-item is-selected" href="/tags/phpquery?p=1" rel="" title="Go to page 2">1</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=2" rel="" title="Go to page 2">2</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=3" rel="" title="Go to page 2">3</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=4" rel="" title="Go to page 2">4</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=5" rel="" title="Go to page 2">5</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=6" rel="" title="Go to page 2">6</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=7" rel="" title="Go to page 2">7</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=8" rel="" title="Go to page 2">8</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=9" rel="" title="Go to page 2">9</a><a class="s-pagination--item js-pagination-item " href="/tags/phpquery?p=10" rel="" title="Go to page 2">10</a></div> </div> <div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar"> <div class="module js-gps-related-tags" id="related-tags"> <h4 id="h-related-tags">Reference</h4> <div data-name="javascript"> <a href="https://php.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">php</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">1429865</span> </span> </div> <div data-name="javascript"> <a href="https://c-cpp.com" class="post-tag no-tag-menu js-gps-track" target="_blank">c/c++</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">756500</span> </span> </div> <div data-name="javascript"> <a href="https://nginx.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">nginx</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49975</span> </span> </div> <div data-name="javascript"> <a href="https://mongodb.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">mongodb</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">159057</span> </span> </div> <div data-name="javascript"> <a href="https://mybatis.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">mybatis</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">3233</span> </span> </div> <div data-name="javascript"> <a href="https://anaconda.org.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">anaconda</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">13410</span> </span> </div> <div data-name="javascript"> <a href="https://pycharm.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">pycharm</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">14671</span> </span> </div> <div data-name="javascript"> <a href="https://python.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">python</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">1902243</span> </span> </div> <div data-name="javascript"> <a href="https://vscode.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">vscode</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">56040</span> </span> </div> <div data-name="javascript"> <a href="https://dockerdocs.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">docker</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">110988</span> </span> </div> <div data-name="javascript"> <a href="https://github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">github</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49000</span> </span> </div> <div data-name="javascript"> <a href="https://flask.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">flask</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">49129</span> </span> </div> <div data-name="javascript"> <a href="https://ffmpeg.github.net.cn" class="post-tag no-tag-menu js-gps-track" target="_blank">ffmpeg</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">24037</span> </span> </div> <div data-name="javascript"> <a href="https://jmeter.net" class="post-tag no-tag-menu js-gps-track" target="_blank">jmeter</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">16910</span> </span> </div> <div data-name="javascript"> <a href="https://matplotlib.net" class="post-tag no-tag-menu js-gps-track" target="_blank">matplotlib</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">63493</span> </span> </div> <div data-name="javascript"> <a href="https://getbootstrap.net" class="post-tag no-tag-menu js-gps-track" target="_blank">bootstrap</a> <span class="item-multiplier"><span class="item-multiplier-x">×</span> <span class="item-multiplier-count">54641</span> </span> </div> </div> </div> </div> </div> <footer id="footer" class="site-footer js-footer" role="contentinfo"> <div class="site-footer--container"> <div class="site-footer--logo"> <a href="https://stackoverflow.com"><svg aria-hidden="true" class="native svg-icon iconLogoGlyphMd" width="32" height="37" viewBox="0 0 32 37"><path d="M26 33v-9h4v13H0V24h4v9h22Z" fill="#BCBBBB"/><path d="m21.5 0-2.7 2 9.9 13.3 2.7-2L21.5 0ZM26 18.4 13.3 7.8l2.1-2.5 12.7 10.6-2.1 2.5ZM9.1 15.2l15 7 1.4-3-15-7-1.4 3Zm14 10.79.68-2.95-16.1-3.35L7 23l16.1 2.99ZM23 30H7v-3h16v3Z" fill="#F48024"/></svg></a> </div> <nav class="site-footer--nav"> <div class="site-footer--col"> <h5 class="-title"><a href="https://stackoverflow.org.cn" class="js-gps-track" data-gps-track="footer.click({ location: 3, link: 15})">Stack Overflow 中文网</a></h5> <p>遵从 CC BY-SA 知识共享许可协议。</p> </div> </nav> </div> </footer> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?709ff2ad9744e86b5b0eee677fc13ede"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-1MW5BV8G8E"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-1MW5BV8G8E'); </script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6117966252207595" crossorigin="anonymous"></script> </body> </html>