편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2019.12.19

    파이썬 유닉스 명령어 실행 방법..


    안녕하세요.. 최근에 파이썬 입문한 파린이 입니다.

    결과값을

    tldextract [결과값] | sort | uniq | grep .com | tr -d ','
    

    이렇게 하여

    twitter com 
    weheartit com 
    www facebook com
    www pinterest com
    www reddit com
    www youtube com
    

    이런식으로 도메인에 대한 정규식 정보만 뽑고 싶은데요, 파이썬에서 유닉스 정규식 표현 사용하는 법을 잘 모르겠습니다.

    <원래 코드 >

     import requests, json, os
    
     url = "http://localhost:5000/search"
    
     data = {
         "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg",
         "resized_images":True # Or true
     }
    
    
     headers = {'Content-type': 'application/json'}
     r = requests.post(url, headers=headers, data=json.dumps(data))              
    
     //r.json to get the response as json
     print(r.json())
    

    위 코드 실행후 결과값을

    tldextract [결과값] | sort | uniq | grep .com | tr -d ','
    

    으로 얻어내고 싶어서 찾아보니 subprocess라는 모듈이 유닉스 코드를 사용 할 수 있도록 도와준다고 하더라구요, 그래서 하기와 같이 코드를 수정해 보았는데,

    AttributeError: module 'subprocess' has no attribute 'a' 
    

    이런 에러가 나오네요

    하기는 제가 수정 해 본 코드 입니다

    cat example1.py

    import requests, json
    import subprocess
    
    url = "http://localhost:5000/search"
    
    data = {
        "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg",
        "resized_images":True # Or true
    }
    
    
    headers = {'Content-type': 'application/json'}
    r = requests.post(url, headers=headers, data=json.dumps(data))
    
    //r.json to get the response as json
    a = r.json()
    imageURL = subprocess.a
    image = imageURL.check_output('| sort | uniq | grep .com | tr -d ','')
    print(image)
    

    어떻게 수정을 해야 제가 원하는 값을 뽑을 수 있을까요??

  • 프로필 정영훈님의 편집
    날짜2019.12.18

    파이썬 유닉스 명령어 실행 방법..


    안녕하세요.. 최근에 파이썬 입문한 파린이 입니다.

    결과값을 tldextract [결과값] | sort | uniq | grep .com | tr -d ',' 이렇게 하여

    twitter com 
    weheartit com 
    www facebook com
    www pinterest com
    www reddit com
    www youtube com
    

    이런식으로 도메인에 대한 정규식 정보만 뽑고 싶은데요, 파이썬에서 유닉스 정규식 표현 사용하는 법을 잘 모르겠습니다.

    <원래 코드 >

     import requests, json, os
    
     url = "http://localhost:5000/search"
    
     data = {
         "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg",
         "resized_images":True # Or true
     }
    
    
     headers = {'Content-type': 'application/json'}
     r = requests.post(url, headers=headers, data=json.dumps(data))              
    
     //r.json to get the response as json
     print(r.json())
    

    위 코드 실행후 결과값을 tldextract [결과값] | sort | uniq | grep .com | tr -d ',' 으로 얻어내고 싶어서 찾아보니 subprocess라는 모듈이 유닉스 코드를 사용 할 수 있도록 도와준다고 하더라구요, 그래서 하기와 같이 코드를 수정해 보았는데,

    AttributeError: module 'subprocess' has no attribute 'a' 이런 에러가 나오네요

    하기는 제가 수정 해 본 코드 입니다

    cat example1.py

    import requests, json
    import subprocess
    
    url = "http://localhost:5000/search"
    
    data = {
        "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg",
        "resized_images":True # Or true
    }
    
    
    headers = {'Content-type': 'application/json'}
    r = requests.post(url, headers=headers, data=json.dumps(data))
    
    //r.json to get the response as json
    a = r.json()
    imageURL = subprocess.a
    image = imageURL.check_output('| sort | uniq | grep .com | tr -d ','')
    print(image)
    

    어떻게 수정을 해야 제가 원하는 값을 뽑을 수 있을까요??

  • 프로필 알 수 없는 사용자님의 편집
    날짜2019.12.18

    파이썬 유닉스 명령어 실행 방법..


    안녕하세요.. 최근에 파이썬 입문한 파린이 입니다.

    결과값을 tldextract [결과값] | sort | uniq | grep .com | tr -d ',' 이렇게 하여 twitter com weheartit com www facebook com www pinterest com www reddit com www youtube com 이런식으로 도메인에 대한 정규식 정보만 뽑고 싶은데요, 파이썬에서 유닉스 정규식 표현 사용하는 법을 잘 모르겠습니다.

    <원래 코드 >

    import requests, json, os

    url = "http://localhost:5000/search"

    data = { "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg", "resized_images":True # Or true }

    headers = {'Content-type': 'application/json'} r = requests.post(url, headers=headers, data=json.dumps(data))

    //r.json to get the response as json print(r.json())

    위 코드 실행후 결과값을 tldextract [결과값] | sort | uniq | grep .com | tr -d ',' 으로 얻어내고 싶어서 찾아보니 subprocess라는 모듈이 유닉스 코드를 사용 할 수 있도록 도와준다고 하더라구요, 그래서 하기와 같이 코드를 수정해 보았는데,

    AttributeError: module 'subprocess' has no attribute 'a' 이런 에러가 나오네요

    하기는 제가 수정 해 본 코드 입니다

    cat example1.py import requests, json import subprocess

    url = "http://localhost:5000/search"

    data = { "image_url":"http://www.mrtt.news/news/photo/201806/147_281_1930.jpg", "resized_images":True # Or true }

    headers = {'Content-type': 'application/json'} r = requests.post(url, headers=headers, data=json.dumps(data))

    //r.json to get the response as json a = r.json() imageURL = subprocess.a image = imageURL.check_output('| sort | uniq | grep .com | tr -d ','') print(image)

    어떻게 수정을 해야 제가 원하는 값을 뽑을 수 있을까요??