Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python beautifulSoup webpage decode problem

I'm trying to scrape the following two pages using beautifulSoap4

Both have the same HTML structure. When I load the first webpage, it's all fine and I get this:

<!DOCTYPE html>
<html dir="rtl" lang="fa-IR">
 <head>
 <style id="litespeed-optm-css-rules">
 ...

But the second webpage output is this:

Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
 �[s�Ƶ(��_���!��3�+ E:�|���lmI����.UИ��&amp; ���!���p���'ە�����~��?1��̩� f0�\ q�
<u*q�"�f��v�[�^}��~|�����e����4� 94�,4�pf�cӗ��̣[="%��[iv*#��0�T:P�kŃ��rӴ�" c��gm_vv۾l�gz���_���yˏ�����8�qw��ȳԕ�:h����="" �@��;��tr�="" �h�:a�="" ��@fy="">
 =���

Here is my python code:

from urllib.request import Request, urlopen
from bs4 import BeautifulSoup as soup
url = 'https://30nama.kim/top/30nama-movie.html'
req = Request(url , headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
page_soup = soup(webpage, "html.parser")
print(page_soup.prettify())

I don't know what happens to the second page and what do these characters mean. I thought I should try to decode it using utf-8 but it didn't work. Any ideas?

Answer*

Draft saved
Draft discarded
Cancel

lang-py

AltStyle によって変換されたページ (->オリジナル) /