douba8048 2016-03-14 11:46
浏览 51

使用Regex解析WP Web Scraping数据

Im using Wordpress plugin "WP Web Scraper" To easily gather some data from a site. The function wpws_get_content returns the result "Raised(number%)" I want to clean this up to just the number. Ive managed to return (90%) with the following code

<p id="number1"><?php echo wpws_get_content('http://my.sportrelief.com/sponsor/sachazarb', '#totalizer_percent', array( 'replace_query' => '/Raised/', 'replace_query_type' => 'regex', 'replace_with' => ' ', ) ); ?></p>

I cant work it out further. Its also, strangly, returning duplicate data, ie

<!--
 Start of web scrap (created by wp-web-scraper)
 Source URL: http://my.sportrelief.com/sponsor/sachazarb
 Query: #totalizer_percent (cssselector)
 Other options: Array
(
    [headers] => 
    [cache] => 60
    [useragent] => WPWS bot (http://windreeladprint.com)
    [timeout] => 2
    [on_error] => error_show
    [output] => html
    [glue] => 

    [eq] => 
    [gt] => 
    [lt] => 
    [query_type] => cssselector
    [remove_query] => 
    [remove_query_type] => cssselector
    [replace_query] => /Raised/
    [replace_query_type] => regex
    [replace_with] =>  
    [basehref] => 1
    [a_target] => 
    [callback_raw] => 
    [callback] => 
    [debug] => 1
    [charset] => UTF-8
)
--><span id="totalizer_percent" class="percent">  (90%)</span><span id="totalizer_percent" class="percent">  (90%)</span><!--
 End of web scrap
 WPWS Cache Control: Remote-fetch via WP_Http
 Computing time: 1.306 seconds
-->
  • 写回答

1条回答 默认 最新

  • douxiduan8344 2016-03-14 11:50
    关注

    You can try this regex Raised\((\d+)%\) and replace with first captured group using \1 or $1.

    <kbd>Regex101 Demo</kbd>

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等