【问题标题】:How to scrape Ajax Call Data in Div by id in PHP如何在 PHP 中通过 id 抓取 Div 中的 Ajax 调用数据
【发布时间】:2023-04-02 06:27:01
【问题描述】:

我想抓取来自webpage 的一些数据,即Cross Reference and Model Information

我有一个抓取所有其他数据表单页面的脚本。

但是由于所需的数据来自 id 的 Div 中的 Ajax 调用。

<div class="inner" style="overflow-x: hidden; overflow-y: scroll; height:300px;" id="xmodellist"><table>
            <tbody><tr>
                <th>Manufacturer</th>
                <th>Model Number</th>
                <th>Description</th>
            </tr>
    
            <tr>
                <td>Amana</td>
                <td><a href="/parts-for-amana-sxd26vw-p1315202w-w.html">SXD26VW</a></td>
                <td>REF - SXS/I&amp;W</td>
            </tr></tbody></table>
    </div>

来自view source的网页Ajax代码

 $.ajax({
                url: "/partmodellist.aspx?partid=" + partid + "&os=" + os.toString(),
                success: function (data) {
                    if (data) {
                        $('#xmodel1').replaceWith(data);

                        $('#xmodellist').scroll(function () {
                            if (($('tr#trxrefloading').length > 0) && $('#xmodellist').scrollTop() + $('#xmodellist').innerHeight() >= $('#xmodellist')[0].scrollHeight) {
                                os = os + 1;
                                $.ajax({
                                    url: "/partmodellist.aspx?partid=" + partid + "&os=" + os.toString(),
                                    success: function (html) {
                                        if (html) {
                                            if (html.trim().length > 0)
                                            {
                                                $("tr#trxrefloading").before(html);
                                            }
                                            else
                                            {
                                                $('tr#trxrefloading').css("display", "none"); 
                                                $('#xmodellist').unbind();
                                            }
                                        } else {
                                            $('tr#trxrefloading').css("display", "none"); 
                                            $('#xmodellist').unbind();
                                        }
                                    }
                                });
                            }
                        });

                    } else {
                        $('xmodel1').css("display", "none"); 
                    }
                }
            });

我想抓取该 div 中的所有信息。

我已附上我的existing code file. or this link

请提供建议,我该如何实现这一目标。

【问题讨论】:

  • 仅供参考,它是 scrape(和 scraperscrapingscraped)不是废品

标签: php ajax dom curl web-scraping


【解决方案1】:

您可以直接使用 CURL 来模拟请求以从 partmodellist.aspx 中获取数据,而不是抓取它或通过 selenium lib 模拟浏览器行为。 What is Selenium?

【讨论】:

    【解决方案2】:

    我也尝试在 php 中 scrape ajax 并发现:

    http://256cats.com/scraping-asp-websites-php-dopostback-ajax-emulation/

    我尝试实现它,但我不是开发人员,所以我的技能有限,我实际上正在尝试做一些比文章中显示的示例更简单的事情。我的意思是:我做不到。我也尝试联系开发者,但没有成功。

    但你可能会感兴趣。

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      相关资源
      最近更新 更多