【发布时间】:2017-05-03 17:31:43
【问题描述】:
import requests
from bs4 import BeautifulSoup
url = input("URL:")
grab_page = requests.get(url)
parse_page = BeautifulSoup(grab_page.text, "html.parser")
file_name = parse_page.title.string.replace("\\,()", "")
newfile = open(file_name + ".html", "w+")
newfile.write(grab_page.text)
当我尝试运行上述代码时,this particular URL, 网页的标题是“如何安装 JDK 8(在 Windows 上, Mac OS、Ubuntu)和 Java 编程入门”我收到以下错误:
Traceback (most recent call last):
File "C:/Users/LKT/PycharmProjects/webpagegrabber/main.py", line 12, in <module>
newfile = open(file_name + ".html", "w+")
OSError: [Errno 22] Invalid argument: 'How to Install JDK 8 (on Windows,\r\nMac OS, Ubuntu)
and Get Started with Java Programming.html'
我哪里做错了?
【问题讨论】:
-
您将
'How to Install JDK 8 (on Windows,\r\nMac OS, Ubuntu) and Get Started with Java Programming.html'传递给open,根据您的操作系统,这不是有效路径。
标签: python replace beautifulsoup