【问题标题】:How to have multiple Context selectors?如何拥有多个上下文选择器?
【发布时间】:2020-03-31 13:26:03
【问题描述】:

我目前正在研究一个刮刀,

我当前的很多代码看起来像这样

contextSelector = 'a[href^="/clubs-and-societies/academic/'; 

(这行得通)

但是有多个页面可供选择,拥有多个 ContextSelector 是行不通的

contextSelector = 'a[href^="/clubs-and-societies/academic/'; 
    contextSelector = 'a[href^="/clubs-and-societies/culture/';
    contextSelector = 'a[href^="/clubs-and-societies/dance/';  

(不工作)

解决办法是什么?

【问题讨论】:

    标签: web-scraping css-selectors


    【解决方案1】:

    两点:

    1) 您的语法格式不正确。应该是:

    contextSelector = 'a[href^="/clubs-and-societies/academic/"]';
    

    (注意结束双引号"和结束方括号]。)

    2) CSS 中的逻辑OR 是逗号,

    contextSelector = 'a[href^="/clubs-and-societies/academic/"], a[href^="/clubs-and-societies/culture/"], a[href^="/clubs-and-societies/dance/"]'; 
    

    【讨论】:

    • 哦,是的,谢谢,我会更正语法。不幸的是,添加 ' , ' 不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    相关资源
    最近更新 更多