我想从网页上提取统计数据。

2024-09-29 16:25:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个简单的python脚本,让我使用“urlopen”命令打开这个url。 http://ffc.coinz.pw/index.php?page=statistics&action=pool

当你到达该网页时,你会看到“一般统计”框。 我想用python脚本只显示“当前难度”旁边的数字

我该怎么做?你知道吗


Tags: 命令脚本httpurl网页indexpageaction
2条回答

这花了大约15分钟的研究时间:

import urllib
import re

url = "http://ffc.coinz.pw/index.php?page=statistics&action=pool"
source = urllib.urlopen(url)
regexp = r">(\d+(?:\.\d*)?)<"
found = 0

for line in source.readlines():
    if found:
            match = re.search(regexp,line)
            break
    if "Current Difficulty" in line:
            found = 1

print match.groups()

您可以自己查看解决此问题的页面:

http://docs.python.org/2/library/re.html

http://docs.python.org/2/library/urllib.html

所用正则表达式的解释:

http://regex101.com/r/kX9jU6

I want to use a python script to ONLY display the number next to "current difficulty"

how do I do that?

  1. 将页面作为原始字符串获取
  2. 使用regex匹配单词“Current difficity”,然后匹配下一个合适的数字/字符串/模式。你知道吗

这是一种方法。你知道吗


如zord所述,在StackOverflow中发布问题之前,请阅读以下内容:

How do I ask a good question?

What topics can I ask about here?

相关问题 更多 >

    热门问题