Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中的HTML文本中查找特殊路径字符串_Python_Regex_Expression - Fatal编程技术网

在python中的HTML文本中查找特殊路径字符串

在python中的HTML文本中查找特殊路径字符串,python,regex,expression,Python,Regex,Expression,我正在尝试提取我读取的HTML文件中的路径。 在本例中,我要寻找的路径是来自谷歌主站点的徽标 我很确定我定义的正则表达式是正确的,但我想我遗漏了一些东西 代码是: import re import urllib a=urllib.urlopen ('https://www.google.co.il/') Text = a.read(250) print Text print '\n\n' b= re.search (r'\"\/[a-z0-9 ]*',Text) print format(b.

我正在尝试提取我读取的HTML文件中的路径。 在本例中,我要寻找的路径是来自谷歌主站点的徽标

我很确定我定义的正则表达式是正确的,但我想我遗漏了一些东西

代码是:

import re
import urllib
a=urllib.urlopen ('https://www.google.co.il/')
Text = a.read(250)
print Text
print '\n\n'
b= re.search (r'\"\/[a-z0-9 ]*',Text)

print format(b.group(0))
我想要得到的实际文本是:

/images/branding/googleg/1x/googleg\u standard\u color\u 128dp.png

如果有人能为我指出正确的方向,我将不胜感激。这可以帮助您:

re.search(r'\"\/.+\"',Text).group(0)
结果:

>>> re.search(r'\"\/.+\"',Text).group(0)
'"/images/branding/googleg/1x/googleg_standard_color_128dp.png"'
以下是我的答案:

import re
import urllib

a=urllib.urlopen ('https://www.google.co.il/')
text = a.read(250)
print text
print '\n\n'
b= re.search (r'\"(\/[a-z0-9_. ]+)+\"',text)


print format(b.group(0))
Run提供:

>>> python stackoverflow.py
<!doctype html><html dir="rtl" itemscope="" itemtype="http://schema.org/WebPage" lang="iw"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop=



"/images/branding/googleg/1x/googleg_standard_color_128dp.png"
python stackoverflow.py