Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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_Html_Parsing - Fatal编程技术网

Python 从“复制html代码”;“字符串”;直到下一次”;“字符串”;

Python 从“复制html代码”;“字符串”;直到下一次”;“字符串”;,python,html,parsing,Python,Html,Parsing,我尝试在一个文件中复制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

我尝试在一个文件中复制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
导入urllib2
html_code=urllib2.urlopen(“网站”)
html\u code\u list=html\u code.readlines()
data=“”
对于html_代码_列表中的行:
line=line.strip()
如果“”在第行中:
#复制数据中的html内容
#直到找到
#中断
试试:

导入urllib2
html_code=urllib2.urlopen(“网站”)
html\u code\u list=html\u code.readlines()
cpy=False
data=“”
对于html_代码_列表中的行:
line=line.strip()
如果“”在第行中:
cpy=True
如果“”在第行中:
cpy=False
如果是cpy:
数据+=行

smart,非常感谢
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