我使用的是Python 3.x. 在使用urllib.request下载网页时,我\n之间的关系很多.我试图使用论坛其他主题中给出的方法删除它,但我无法这样做.我用过strip()功能和replace()功能......但没有运气!我在eclipse上运行这段代码.这是我的代码:
import urllib.request
#Downloading entire Web Document
def download_page(a):
opener = urllib.request.FancyURLopener({})
try:
open_url = opener.open(a)
page = str(open_url.read())
return page
except:
return""
raw_html = download_page("http://www.zseries.in")
print("Raw HTML = " + raw_html)
#Remove line breaks
raw_html2 = raw_html.replace('\n', '')
print("Raw HTML2 = " + raw_html2)
Run Code Online (Sandbox Code Playgroud)
我无法发现\n在raw_html变量中获得大量内容的原因.