Ich versuche, Programm zu machen, um jedes Wort zu senden() BeautifulSoup dann drucken Sie das Ergebnis. zum Beispiel, wenn ich das „Hallo“ Wort (http://upodn.com/phon.php) Website einreichen das Ergebnis: həlo
, aber wenn ich das „Hallo“ Wort mit meinem Skript eintragen des Ergebnis: həlo
wie Unicode Ergebnis in BeautifulSoup
Wie ich das Ergebnis drucken wie es in der Website erscheint =>?
Script:
# -*- coding: utf-8 -*-
import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup
import html2text
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'), ('Content-type', 'text/html; charset=utf-8')]
br.open('http://upodn.com/phon.php')
br.select_form(nr=0)
br.form['intext'] = 'hello'
br.submit()
data = br.response().read()
soup = BeautifulSoup(data)
# print soup
table = soup.find('table', {'rules': 'cols'})
result = []
for row in table.findAll("font"):
d = row.text
result.append(d)
print result[1]
Ausgang:
həlo
[Finished in 2.7s]
Zuerst verwenden Sie die veraltete Version von BeautifulSoup; die aktuelle Version ist das Paket und Modul 'bs4' –