Chrome dirver 크롤링_1_수정(url추가)

조회수 1382회

Problem_1

url ='https://play.google.com/store/apps/details?id=tools.photo.hd.camera&hl=en'

title = driver.find_element_by_xpath('//title')

print(title.get_attribute('content'))

이 코드의 결과로 None 나옵니다. 아무것도 찾아오지를 못합니다.

Problem_2

    url ="'https://play.google.com/store/apps/details?id=tools.photo.hd.camera&hl=en'"
    driver.get(url)
    page = driver.page_source

    soup = BeautifulSoup(page, "html.parser")

    table = soup.find("div", class_="id-app-title")

    print("App name: ", table.string)

AttributeError: 'NoneType' object has no attribute 'string' 라는 에러메세지로 인해서 requrests 이용하여 코드를 조금 변경했습니다

page = requests.get(url).text
soup = BeautifulSoup(page, "html.parser")
table = soup.find("div", class_="id-app-title")

print("App name: ", table)

그래서 결과를 뽑아보니 App name: None 이라고 나옵니다 ㅠ 왜 계속 내용을 뽑아오지 못하고 있는걸까요 예전에 사람인 API를 통해서 했을때는 div 클래스 이름만 맞추면 잘 뽑아 왔는데 google플레이 스토어에서는 div class 이름을 매칭을 시켜도 다 none 값이 나옵니다 ㅜㅠㅜ

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 정확한 url 값이 뭔가요? 구글플레이 스토어라고만 되어 있는데 정확한 주소가 없네요. 정영훈 2019.11.30 23:33
  • 'https://play.google.com/store/apps/details?id=tools.photo.hd.camera&hl=en' 이 url을 사용했습니다! 알 수 없는 사용자 2019.12.1 16:08
  • 주어진 링크 내용(html)에는 id-app-title id 나 class가 없어요. 정영훈 2019.12.1 20:33
  • 아.. 그럼 저 url에 span jsname="bN97Pc"에 있는 텍스트(리뷰)를 뽑아올려면 soup.find_all("span", jsname="bN97Pc")이렇게 하는게 틀린건가요? 알 수 없는 사용자 2019.12.3 14:51
  • 명확하게 추출하고 싶은 항목을 적어보시기 바랍니다. 그런데 몇가지 확인을 해보니 id, class 값을 동적으로 변경합니다. 즉 id, class 값으로는 추출할 수 없습니다. child parent 등 구조로 찾아야 할 듯 합니다. 간단하지 않습니다. 정영훈 2019.12.3 19:17
  • 저는 리뷰 텍스트, 각 리뷰별 별점 레이팅, 다운로드 수 등 이런 정보들을 추출하고 싶습니다. 알 수 없는 사용자 2019.12.4 10:10

1 답변

  • 자세히 보니 class 값등이 고정이네요.

    import requests
    import bs4
    
    contents = requests.get('https://play.google.com/store/apps/details?id=tools.photo.hd.camera&hl=en').content
    bs = bs4.BeautifulSoup(contents, 'html.parser')
    
    text = bs.find('div', attrs={'jsname':"sngebd"})
    
    print(text)
    
    <div jsname="sngebd">HD camera lets you easily shoot HD photos and videos, and offers beautiful filters, and panorama photo mode! 🎊🎉💯<br/><br/>📷 <b>Features:</b><br/>* Optical / digital zoom, tap to focus, focus halo display<br/>* AF mode (infinity, Macro )<br/>* White Balance ( Auto, Fluorescent, white, daylight, cloudy )<br/>* Countdown pictures<br/>* Set the photo size<br/>* Record the shooting location information<br/>*Adjust exposure<br/>* View mode ( sports, night, sunset, party )<br/>*The front and the rear camera toggle<br/>* Shoot and produce a panoramic photo, take immersive panorama<br/>* Viewfinder display sensor can capture the full screen, and not crop the image<br/>* Panorama mode requires the use of a gyro sensor<br/>* For Android 4.0 and higher versions of phones and tablets<br/><br/>------------------<br/>💎 <b>Disclaimer:</b><br/>This app is based on native android camera code and licensed under the Apache License.<br/>Apache Licens: http://www.apache.org/licenses/LICENSE-2.0.html</div>
    
    • 리뷰는 자바스크립트를 이용해서 동적으로 작업합니다. requests 만으로는 어려우니 selenium을 이용하세요. 정영훈 2019.12.4 11:34
    • 현재 selenium Chromedriver를 사용하고 있습니다. 현재 requests와 selenium을 두 버전으로 만들어서 만들어 보고 있습니다. 모델은 github에서 가져온 코드를 이용하고 있는데 결과값이 나오지 않아서 애먹고 있었어요 알 수 없는 사용자 2019.12.4 13:38
    • 아 죄송하지만 attrs가 어떤것을 뜻하는지 알 수 있을까요 알 수 없는 사용자 2019.12.4 13:45
    • https://www.crummy.com/software/BeautifulSoup/bs4/doc/#attrs 문서를 읽어보세요 정영훈 2019.12.4 23:21

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)