Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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 我们可以找到一个标记,该标记显示一个属性,但它';s值未知_Python_Html_Python 3.x_Beautifulsoup - Fatal编程技术网

Python 我们可以找到一个标记,该标记显示一个属性,但它';s值未知

Python 我们可以找到一个标记,该标记显示一个属性,但它';s值未知,python,html,python-3.x,beautifulsoup,Python,Html,Python 3.x,Beautifulsoup,假设我想检索所有标签p谁获得了属性ID,但属性的值未知 <p id=?, ... > 使用靓汤的最佳方法是什么?只需使用汤。查找所有('p')。这样,您将获取所有标记,忽略id属性 然后,您可以验证每个解析行中是否存在术语“id=“” 示例代码: p_tags = soup.find_all('p') for item in p_tags: if 'id=' in str(item): print(item) else: pri

假设我想检索所有标签
p
谁获得了属性ID,但属性的值未知

<p id=?, ... >


使用靓汤的最佳方法是什么?

只需使用
汤。查找所有('p')
。这样,您将获取所有
标记,忽略
id
属性

然后,您可以验证每个解析行中是否存在术语
“id=“

示例代码:

p_tags = soup.find_all('p')

for item in p_tags:
    if 'id=' in str(item):
        print(item)
    else:
        print("Attr ID not present in this line!")

只需使用
汤。查找所有('p')
。这样,您将获取所有
标记,忽略
id
属性

然后,您可以验证每个解析行中是否存在术语
“id=“

示例代码:

p_tags = soup.find_all('p')

for item in p_tags:
    if 'id=' in str(item):
        print(item)
    else:
        print("Attr ID not present in this line!")

检查是否存在:

soup.find_all('p', id=True)

检查是否存在:

soup.find_all('p', id=True)

只需使用
汤。查找所有('p')
。这样,您将获取所有
标记,忽略
id
标记。然后,您可以验证每个提取行中是否存在术语“id=”。如何检查id是否存在?你能把它写下来作为答案吗?只需使用
soup.find_all('p')
。这样,您将获取所有
标记,忽略
id
标记。然后,您可以验证每个提取行中是否存在术语“id=”。如何检查id是否存在?你能把它写下来作为答案吗?