Programming版 - Python: how to match the price string starting with $ ? |
|
|
|
|
|
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 [$] ?
|
|
|
|
相关主题 |
---|
● 用python生成傻shell脚本如何? | ● Re: 问个google面试题 (转载) | ● C++ Strategies and Tactics 书上一个问题求助 | ● python的问题,大拿帮忙看看 | ● Python: 有一个混合了子list和string的list, 如何判断元素是list还是string? | ● 多文本搜索多个字符串 | ● python gc question | ● perl的文本处理大部分容易在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用 |
|
|
|