import os
使用这段代码创建一个文件,这个方法将在while循环中使用
def get_data(self,url):
pagina = urllib.request.urlopen(self.url)
data = BeautifulSoup(pagina, "html.parser")
dest = "C:\\Users\\Dennis.Pieruschka\\Documents\\Scraper\\Links"
html = ".html"
brackets = "\\"
string = dest + brackets + url + html
with open(string, 'w') as f:
f.write(data)
f.close()
Somehow i cant parse in the name of the URL and use it to name the file
Somebody knows how to fix it i get this error
OSError: [Errno 22] Invalid argument: 'C:\\Users\\Dennis.Pieruschka\\Documents\\Scraper\\Links\\http://www.visservanbaars.nl/vacatures/senior-oracle-dba-osb-weblogic/.html'
问题是:文件名中不能有:和/将被解释为目录分隔符。 你可以这样做
然而,更好的解决方案是对所有特殊字符进行编码 导入urllib.parse encoded_url=urllib.parse.quote(url)
在Windows中,文件名上不能有:或\或/
相关问题 更多 >
编程相关推荐