Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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 让BeautifulSoup以不区分大小写的方式捕获标记_Python_Html_Parsing_Beautifulsoup_Case Insensitive - Fatal编程技术网

Python 让BeautifulSoup以不区分大小写的方式捕获标记

Python 让BeautifulSoup以不区分大小写的方式捕获标记,python,html,parsing,beautifulsoup,case-insensitive,Python,Html,Parsing,Beautifulsoup,Case Insensitive,我想用BeautifulSoup捕捉一些标签:一些标签,一些标签,一些标签。但不管他们的情况如何,我都想抓住他们;我知道有些网站是这样做的:,我希望能够抓住这一点 我注意到BeautifulSoup默认情况下区分大小写。如何以不区分大小写的方式捕获这些标记?您可以使用不区分大小写的标记: import BeautifulSoup html = '''<html> <head> <meta name="description" content="Free Web t

我想用BeautifulSoup捕捉一些标签:一些
标签,一些
标签,一些
标签。但不管他们的情况如何,我都想抓住他们;我知道有些网站是这样做的:
,我希望能够抓住这一点

我注意到BeautifulSoup默认情况下区分大小写。如何以不区分大小写的方式捕获这些标记?

您可以使用不区分大小写的标记:

import BeautifulSoup

html = '''<html>
<head>
<meta name="description" content="Free Web tutorials on HTML, CSS, XML" /> 
<META name="keywords" content="HTML, CSS, XML" /> 
<title>Test</title>
</head>
<body>
</body>
</html>'''

soup = BeautifulSoup.BeautifulSoup(html)
for x in soup.findAll('meta'):
    print x
导入美化组
html=“”
试验
'''
soup=BeautifulSoup.BeautifulSoup(html)
对于汤中的x.findAll('meta'):
打印x
结果:

<meta name="description" content="Free Web tutorials on HTML, CSS, XML" /> <meta name="keywords" content="HTML, CSS, XML" />
BeautifulSoup标准化了输入时的解析树。它将标记转换为小写。您不必担心IMO。

啊,那么BeautifulSoup会将所有标记转换为小写吗?属性呢?这是否意味着我也可以使用
find
而不是
findAll
,它仍然不区分大小写?@cool RR:Yes find的工作方式与findAll类似。区分大小写取决于你在做什么。好吧,现在我试过了,它会将属性转换成小写。