没有得到BeautifulSoup的确切文字

时间:2017-07-05 08:19:38

标签: python beautifulsoup html-parser

我正在尝试从HTML页面获取确切文本,但输出文本与预期文本不同。

  

HTML页面上的文字

Салнас 14
  

textSoup显示的文字

ĐĄĐ°ĐťĐ˝Đ°Ń 14

我的代码是

page = BeautifulSoup(url.read(),'html.parser')
page.find(id='tdo_11').text
  

Html检查div的代码

<td class="ads_opt" id="tdo_11" nowrap=""><b>Салнас 14</b></td>

我不明白是什么原因导致的? 我应该使用不同的解析器吗?

1 个答案:

答案 0 :(得分:1)

使用import requests response = requests.get('https://www.ss.lv/msg/ru/real-estate/flats/riga/plyavnieki/onlol.html') page = BeautifulSoup(response.text, 'html.parser') 库来发出HTTP请求,它比Python内置的要好得多,原因有很多。它自动而智能地处理编码。

# install vue-cli
$ npm install --global vue-cli
# create a new project using the "webpack" template
$ vue init webpack my-project
# install dependencies and go!
$ cd my-project
$ npm install
$ npm run dev
相关问题