2012-06-12 63 views
1

我使用雅虎管道來構建一個刮板,通過xPath刮掉我們公司的微站點,並生成一個RSS源,然後我可以在主站點上嵌入。在雅虎管道中用正則表達式掙扎

到目前爲止,我儘可能從頁面上抓取工作職位和地點,但我無法獲得項目鏈接到微站點。

這裏是到目前爲止我的菸斗:http://pipes.yahoo.com/pipes/pipe.info?_id=2bb5b8fedd0064b64d0e8861e3fc8fd5

我想我需要提取每個節點的HREF鏈接,然後應用正則表達式,但我真的不能讓我的頭周圍。

鏈接看起來像這樣的代碼:www2.jobs.badenochandclark.ch/JavaScript:OpenAssignment('a960c93a-11fe-4751-bc27-83a48429c3ba',%20'/Jobs/Details/a960c93a-11fe-4751 -bc27-83a48429c3ba');

但我在努力產生一個正則表達式,將基本做到這一點: www2.jobs.badenochandclark.ch/ 的JavaScript:OpenAssignment( 'a960c93a-11fe-4751-bc27-83a48429c3ba',%20' /Jobs/Details/a960c93a-11fe-4751-bc27-83a48429c3ba ');

所以我堅持如何提取一個鏈接,然後如何建立到管道。任何幫助或推動正確的方向將非常感激。

回答

0

全面的URL解析並不簡單,但給了足夠的限制,它變得易於管理。

例如,如果你知道

  1. JavaScript:OpenAssignment(始終遵循/
  2. ,第一個參數始終是在引號中的十六進制+短線串,
  3. 的第二個參數(至少您需要的部分)也在引號中,
  4. 並且您可以在「功能」後丟棄URL的其餘部分,

事遂所願,這可能是一個起點:

\/JavaScript:OpenAssignment\([^'"]*['"][0-9a-fA-F\-]+['"][^,)]*,[^'")]*['"]([0-9a-fA-F\-]+)['"].* 

然後,$1將包含你的願望,以保持匹配。解釋如下。

\/       Slashes need to be escaped (usually). 
JavaScript:OpenAssignment Our function of interest. 
\(       Parentheses need to be escaped too. 
[^'"]*      We're looking for a quote next, so ignore any 
          string of non-quotes, e.g. %20. 
['"]       A quote character. 
[0-9a-fA-F\-]+    A hexadecimal-and-dashes string. 
['"]       A quote character. 
[^,)]*      We're looking for a comma next, so ignore any 
          string of non-quotes, e.g., again, %20. 
,       A comma character. 
[^'"]*      We're looking for a quote again, so ignore any 
          string of non-quotes, e.g. %20. 
['"]       A quote character. 
([0-9a-fA-F\-]+)    A hexadecimal-and-dashes string, this time captured. 
['"]       A quote character. 
.*       The rest of the string that we don't care about. 
1

在這裏,你去.. http://pipes.yahoo.com/pipes/pipe.info?_id=d564b802185d5777d757ed4189470941

正則表達式模塊中使用略顯不足複雜的代碼。它往往是更容易清除你不想比試圖提取並分配給一個變量

plx.link.href找到這個 - >的JavaScript(+)工作替換與 - >代碼jobs

in plx.link。href find this->\'\);替換爲 - >保留空白

代碼的尾部位');需要反斜槓'是控制字符加反斜槓\使得正則表達式可以將它們作爲文本字符大致地讀取它們。

正則表達式的該位一個(。+?)b指比賽或搶& B之間的一切,就派上用場了這樣的事情很多。

+0

謝謝!我不知道(。+?)b。該解決方案令人驚歎! – user1450894

相關問題