由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Python: how to match the price string starting with $ ?
相关主题
要不要学习 scripting languages such as Python?Python, Java, Perl, PHP,Ruby
[合集] 统一的regex (grep, sed, awk, python,..)python的re怎么有很多莫名奇妙的行为, 我估计是bug吧
现在哪些script最流行?python能检查出space是一个还是两个吗?
问个java regex基本问题写Python 的苦恼之一:有人当c用,有人当bash用,有人当FP用。当然也有人当python用
Re: 问个google面试题 (转载)王垠对google的看法 (转载)
python的问题,大拿帮忙看看regex probelm
多文本搜索多个字符串parsing file in node: js or python ?
perl的文本处理大部分容易在python里实现吗?用python生成傻shell脚本如何?
相关话题的讨论汇总
话题: strong话题: python话题: string话题: 699话题: dell
进入Programming版参与讨论
1 (共1页)
w*s
发帖数: 7227
1
Hi,
say the original string is
  • Dell Small Business offers the Dell OptiPlex 7010 business desktop for $699 (
    was $1085.86) with free shipping.

  • what i want to do is,
    if find "desktop", return it's price. 699 in this case.
    i tried sth. like this if i remember correctly,
    pattern = "desktop*" + "(.*)"
    m = re.search(pattern, web_pg)
    if m:
    print "tPrice:", m.group(2)
    it always come back with $699. But i want to get rid of that $.
    if i do "($*)",
    doesn't work.
    Any suggestions ? Thanks !
    c********l
    发帖数: 8138
    2
    regex里面$号是特殊字符,所以需要用中括号escape掉
    最后regex就是 "[$](.*)"
    BTW,看来现在随便什么新手都能写网页价格爬虫,
    出于今后过度竞争的可能性,本人决定退出此行业,lol
    w*s
    发帖数: 7227
    3
    brother, i tried $ before and didn't work.
    haven't tried your yet, but any difference between
    $ and [$] ?

    【在 c********l 的大作中提到】
    : regex里面$号是特殊字符,所以需要用中括号escape掉
    : 最后regex就是 "[$](.*)"
    : BTW,看来现在随便什么新手都能写网页价格爬虫,
    : 出于今后过度竞争的可能性,本人决定退出此行业,lol

    l*********s
    发帖数: 5409
    4
    one is special character, and the latter is normal single character.

    【在 w*s 的大作中提到】
    : brother, i tried $ before and didn't work.
    : haven't tried your yet, but any difference between
    : $ and [$] ?

    1 (共1页)
    进入Programming版参与讨论
    相关主题
    用python生成傻shell脚本如何?Re: 问个google面试题 (转载)
    C++ Strategies and Tactics 书上一个问题求助python的问题,大拿帮忙看看
    Python: 有一个混合了子list和string的list, 如何判断元素是list还是string?多文本搜索多个字符串
    python gc questionperl的文本处理大部分容易在python里实现吗?
    要不要学习 scripting languages such as Python?Python, Java, Perl, PHP,Ruby
    [合集] 统一的regex (grep, sed, awk, python,..)python的re怎么有很多莫名奇妙的行为, 我估计是bug吧
    现在哪些script最流行?python能检查出space是一个还是两个吗?
    问个java regex基本问题写Python 的苦恼之一:有人当c用,有人当bash用,有人当FP用。当然也有人当python用
    相关话题的讨论汇总
    话题: strong话题: python话题: string话题: 699话题: dell