파이썬 urlopen 모듈에러

from urllib.request import urlopen
from bs4 import BeautifulSoup

위와 같이 작성하면 아래와 같은 에러가 납니다.

Traceback (most recent call last):
  File "t.py", line 2, in <module>
    from urllib.request import urlopen
ImportError: No module named request

urllib2 로 변경하면 됩니다.

from urllib2 import urlopen
from bs4 import BeautifulSoup

이제 다시 테스트 해보세요~

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

인코딩을 페이지에 맞는 euc-kr 또는 utf-8 로 바꿔주면 됩니다.

[root@ivps ~]# python
Python 2.7.5 (default, Apr  9 2019, 14:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> rs = req.session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'req' is not defined
>>> rs = requests.session()
>>> post = rs.get('https://ivps.tistory.com/')
>>> print post.text
<!doctype html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <title>TISTORY</title>
    <link rel="stylesheet" type="text/css" href="//t1.daumcdn.net/tistory_admin/www/style/top/font.css">
    <link rel="stylesheet" type="text/css" href="//t1.daumcdn.net/tistory_admin/www/style/top/error.css">
</head>
<body>
<div id="kakaoIndex">
    <a href="#kakaoBody">본문 ���기</a>
    <a href="#kakaoGnb">�� ���기</a>
</div>
>>> post.encoding
'ISO-8859-1'
>>> post.encoding = 'utf-8'
>>> print post.text
<!doctype html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <title>TISTORY</title>
    <link rel="stylesheet" type="text/css" href="//t1.daumcdn.net/tistory_admin/www/style/top/font.css">
    <link rel="stylesheet" type="text/css" href="//t1.daumcdn.net/tistory_admin/www/style/top/error.css">
</head>
<body>
<div id="kakaoIndex">
    <a href="#kakaoBody">본문 바로가기</a>
    <a href="#kakaoGnb">메뉴 바로가기</a>
</div>

post.encoding = 'utf-8'

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

[CentOS] Python PIP 설치

Python 2019. 8. 19. 09:41

[root@ivps ~]# pip
-bash: pip: command not found

[root@ivps ~]# yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * epel: mirrors.aliyun.com
 * extras: mirror.kakao.com
 * remi-php72: mirror.innosol.asia
 * remi-safe: mirror.innosol.asia
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch            Version               Repository     Size
================================================================================
Installing:
 python2-pip          noarch          8.1.2-10.el7          epel          1.7 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.7 M
Installed size: 7.2 M
Is this ok [y/d/N]: y
Downloading packages:
python2-pip-8.1.2-10.el7.noarch.rpm                        | 1.7 MB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pip-8.1.2-10.el7.noarch                              1/1
  Verifying  : python2-pip-8.1.2-10.el7.noarch                              1/1

Installed:
  python2-pip.noarch 0:8.1.2-10.el7

Complete!

패키지가 없다고 나오면 epel-release 를 먼저 설치하세요~

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

티스토리에 2차 도메인으로 개인 도메인이 연결되어 있었는데 보안사이트가 적용되지 않아서 과감히 연결을 해제했습니다.

1차와 2차 모두 네이버 웹마스터 도구에 등록이 되어 있는데도 하나를 지웠더니 방문수가 급격하게 줄어들었네요~

유입 감소를 해결하기 위한 방법에 대해서 알아보겠습니다.

티스토리 개인 도메인 연결 해제 후 검색유입 감소

검색 유입다음에서만 되는 것 같습니다.

며칠 좀 더 지켜봐야겠네요~

 

개인도메인 삭제한지 딱 7일이 지났는데, 네이버, 구글 실망입니다~ ㅋ

중복 사이트 패널티 먹은건지 잘 모르겠지만 1차 도메인 주소로 검색 색인현황을 보니 좀 더딘 것 같습니다.

네이버 웹마스터도구 색인현황

 

▶ 1차 조치사항 ( 7일이 지난 후 )

  ☞ 기존 2차 도메인 호스트를 가상서버에 웹서비스를 구축하고 .htaccess 작성해서 1차 도메인으로 리다이렉트 적용

      한번 지켜봐야겠네요~

      효과가 있네요~ 예전만 못하지만 기존 2차 도메인 주소 타고 리디렉션 되어서 오는 것 같습니다.

 

▶ 검색유입 감소 해결 방법

  ☞ 1차 도메인 네이버 및 구글 웹마스터도구에 사이트 주소 등록

  ☞ 기존 2차 도메인 주소를 1차로 리디렉션 하기

RewriteEngine On

RewriteCond %{HTTP_HOST} ^blog\.ivps\.kr$ [NC]
RewriteRule ^(.*)$ https://ivps.tistory.com%{REQUEST_URI} [R=301,L]

제 블로그 주소를 예로 들었는데 본인의 블로그 주소에 맞게 수정하시면 됩니다.

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,