我正在尝试实现对网站的获取请求,获取html并将其附加到列表中。问题是它在随机的位置添加了\n
,我需要编写一个脚本来解决该问题。我已经尝试过strip()
和replace()
及其之间的所有操作。
这是我的代码:
r = requests.get(page)
data = r.text
html = BeautifulSoup(data,"html.parser")
for lin in html.find_all("link",href=True):
if "css" in lin['href']:
urls.append(lin['href'])
for url in urls:
if "http" in url:
sourcecode.append(data)
我只需要从源代码中删除\n
。