我尝试在文件中复制 HTML 代码的一部分,我如何从一个值到下一个值,我尝试使用 python 来完成它。
这是我的代码:
import urllib2
html_code = urllib2.urlopen("web site")
html_code_list = html_code.readlines()
data = ""
for line in html_code_list:
line = line.strip()
if '<A NAME="table8">' in line :
#copy the html contents in data
#until find <!**********************************************>
#break
最佳答案
尝试:
import urllib2
html_code = urllib2.urlopen("web site")
html_code_list = html_code.readlines()
cpy = False
data = ""
for line in html_code_list:
line = line.strip()
if '<A NAME="table8">' in line:
cpy = True
if '<!**********************************************>' in line:
cpy = False
if cpy:
data += line
关于python - 复制 html 代码从 "string"到下一个 "string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57588913/