“如何忽略”\";在python中使用正则表达式时

“如何忽略”\";在python中使用正则表达式时,python,http,re,Python,Http,Re,我对正则表达式、http请求和使用python获取网页都很陌生。我正在尝试获取网页并在p标记中查找所有部分,但我的搜索失败,因为我获取的html具有\n。以下是我目前掌握的代码: # Search for link values within URL input import urllib.request, urllib.parse, urllib.error import re import ssl # Ignore SSL certificate errors ctx = ssl.creat

我对正则表达式、http请求和使用python获取网页都很陌生。我正在尝试获取网页并在p标记中查找所有部分,但我的搜索失败,因为我获取的html具有\n。以下是我目前掌握的代码:

# Search for link values within URL input
import urllib.request, urllib.parse, urllib.error
import re
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE


url = input('Enter - ')

html=urllib.request.urlopen(url, context=ctx).read()
print(html)

areas=re.findall(b"(?m)<p>.+</p>", html)
print(len(areas))
for i in range(len(areas)):
    print(areas[i].decode)
#在URL输入中搜索链接值
导入urllib.request、urllib.parse、urllib.error
进口稀土
导入ssl
#忽略SSL证书错误
ctx=ssl.create\u default\u context()
ctx.check_hostname=False
ctx.verify_mode=ssl.CERT_NONE
url=input('Enter-')
html=urllib.request.urlopen(url,context=ctx.read())
打印(html)
areas=re.findall(b“(?m)+

”,html) 打印(透镜(区域)) 对于范围内的i(透镜(面积)): 打印(区域[i]。解码)

使用网站:

您可以通过执行
html来删除所有
\n
s。replace(“\n”,”)
,这将用零替换所有
\n
s