简体   繁体   English

在python程序上需要帮助。 如何从HTML搜索和保存ID

[英]Needing help on a python program. How to search and save IDs from a HTML

Currently I'm trying to write a program that will search for a tag and the characters in front of that tag (until a space or enter) on a html local file but i don't know how, I worte some code but it isn't working, it only lists all the text on the html instead of looking for the PA and the characters. 目前,我正在尝试编写一个程序,该程序将在html本地文件上搜索标签和该标签前面的字符(直到空格或输入),但我不知道如何,我编写了一些代码,但事实并非如此无效,它仅列出html上的所有文本,而不是查找PA和字符。

Here's my code so far: 到目前为止,这是我的代码:

from bs4 import BeautifulSoup
import re

ecj_data = open('output.html', 'r').read()
soup = BeautifulSoup(ecj_data, 'lxml')
d = 'PA'
soup_strings = [ l for l in list(soup.strings) if l.strip() != '' ]
for s in soup_strings :
    print(s)

Do you mean to search word including 'PA'? 您是要搜索包括“ PA”在内的单词吗? Please try below. 请尝试以下。

for i in soup.strings.split(' '):
    if 'PA' in i:
        print (i)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我将文件(.jpg)保存在另一个文件夹中,我想在我的 python 程序中使用该文件。 我如何导入它们 - i save files(.jpg) in another folder and i want to use that files in my python program. how do i import them python程序。 苹果问机 - python program. apple asking machine Python curses程序。 什么字符是^? - Python curses program. What char is ^? 构建一个程序。 Python中的类和函数 - Structuring a program. Classes and functions in Python Matplotlib-如何在不需要保存的情况下从图中去除多余的空白? - Matplotlib - How to strip extra whitespaces from a plot without needing to save it? 我需要将用户输入变量作为此列表传递,例如:python 程序下方的 [1, 3, 6, 4, 1, 2]。 有人可以帮我吗 - I need to pass a user input variable as this list eg: [1, 3, 6, 4, 1, 2] in below python program. Could some one help me 为另一个 Python 程序创建 UI。 如何在 tkinter 中为 Python 3 打印 label? - Creating a UI for another Python program. How do I make a printing label in tkinter for Python 3? 从我的小型 Python 套接字程序中获取错误。 返回“OSError: [WinError 10022] 提供了无效的参数” - Getting an error from my small Python sockets program. Returns “OSError: [WinError 10022] An invalid argument was supplied” Python>保存help()输出到格式化的html文件? - Python > Save help() output to formated html file? 如何将 Python 与我的 MFC 程序同步。(我使用 Pywin32 Lib) - How to synchronize Python with my MFC program.(I using Pywin32 Lib)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM