【发布时间】:2015-10-21 15:45:27
【问题描述】:
这是我的代码:
#!C:/Python27/python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import urllib2
import sys
import urlparse
import io
url = "http://www.dlib.org/dlib/november14/beel/11beel.html"
#url = "http://eqa.unibo.it/article/view/4554"
#r = requests.get(url)
html = urllib2.urlopen(url)
soup = BeautifulSoup(html, "html.parser")
#soup = BeautifulSoup(r.text,'lxml')
if url.find("http://www.dlib.org") != -1:
div = soup.find('td', valign='top')
else:
div = soup.find('div',id='content')
f = open('path/file_name.html', 'w')
f.write(str(div))
f.close()
抓取那些网页,我发现一些非AScii 字符到从该脚本编写的html 文件中,我需要将其删除或解析为可读字符。 有什么建议吗?谢谢
【问题讨论】:
-
你写的脚本没有报错,非ascii字母有什么问题?,你现在要在你写的文件里吗?
-
我知道没有错误,但我需要删除 HTML 中的一些字符,例如“”。
-
@Poggio 可能会有所帮助stackoverflow.com/questions/17732695/…
标签: python html character-encoding web-scraping beautifulsoup