python - 复制 html 代码从 "string"到下一个 "string"

标签 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 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/

相关文章:

python - epel-release repo 缺少 repomd.xml

python - UTF-16 转 Ascii 忽略十进制值大于 127 的字符

javascript - 将javascript垂直居中应用于多个div

javascript - 网页动画背后的技术是什么?

javascript - JSON解析文件路径

python - 无法安装Numpy+MKL

python - 这个 Numpy 形状是什么意思?

html - css缩放后的空白

java - Intellij解析java代码

c# - 非标准时区字符串的 DateTime.ParseExact 问题