【问题标题】:Simple bing "trending searches" scraper with apify带有 apify 的简单 bing“趋势搜索”刮板
【发布时间】:2021-02-21 23:28:13
【问题描述】:

我对抓取/apify 非常陌生,但我正在尝试做一些简单的事情,当搜索文本框成为焦点时,在 bing.com 上获取“趋势搜索”。

目前,我有:

async function pageFunction(context) {
  
function myTrim(x) {
  return x.replace(/^\s+|\s+$/gm,'');
}
  
    const $ = context.jQuery;

    // log an alert when the search box gets focus
    $( "#sb_form_q").focus(function() {
      context.log.info('focus on the input box');
    });

    $("#sb_form_q").focus();

    // wait for the resulting div to appear 
    context.waitFor('#sw_as');
    context.log.info('div #sw_as appeared');
    
    const myTerm = $("li div.sa_tm").find("span.sa_tm_text").text();

    // Return an object with the data extracted from the page.
    // It will be stored to the resulting dataset.
    return {
        myTerm
    };
}

正如我所说,我对 apify/actors 比较陌生,因此我将不胜感激。我认为它应该很简单,但它只是没有点击。感谢您的帮助。

【问题讨论】:

    标签: jquery bing apify


    【解决方案1】:

    您似乎想要的是针对先前输入的查询的建议,这些查询在单击搜索字段后出现,虽然您的代码本身可以正常工作,但这些建议仅适用于 cookie 中持续存在的某些浏览会话,理论上甚至取决于特定的IP 但情况似乎并非如此,因此要恢复以前的用户会话,您需要做的就是先将 cookie 加载到页面中。在这里看看如何做到这一点:http://docs.apify.com/tutorials/log-in-by-transferring-cookies

    【讨论】:

    • 您好,感谢您的回复,但我不确定这是否完全正确。即使在没有输入任何内容的情况下设置了焦点,必应也会提供“趋势”搜索结果(建议)。就国家/地区而言,它可能取决于 IP,这很好,但是即使没有输入任何内容,LI 列表中的建议也会出现,只是在焦点上。它们与以前的搜索无关
    • @Trutter 事实上,通过代理的行为是不同的。您查询的元素似乎确实存在。在这种情况下,我建议使用 docs.apify.com/tutorials/… 进行可视化调试
    猜你喜欢
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2012-02-26
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    相关资源
    最近更新 更多