知道解决方案的人
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'发布于 2017-09-29 01:28:26
在Windows中,文件名上不能有:或\或/
发布于 2017-09-29 01:28:51
问题是您不能在文件名中包含:,并且/将被解释为目录分隔符。你可以这样做
encoded_url = url[5:] #remove 'http:
encoded_url = encoded_url.replace('/','-' # replace / with -但是,更好的解决方案是对所有特殊字符进行编码,导入urllib.parse encoded_url = urllib.parse.quote(url)
https://stackoverflow.com/questions/46475036
复制相似问题