vendredi 25 mai 2018

python 'NoneType' object has no attribute 'decompose'

from bs4 import BeautifulSoup
import time
#import requests
import urllib.request,re
#import pandas as pd
#import numpy as np
import csv

def crawlcontents():
    url = 'https://www.tripadvisor.com/ShowTopic-g983296-i13236-k11538516-Rent_from_LOTTE_standard_or_mystery_option-Jeju_Island.html' 

    html = urllib.request.urlopen(url).read().decode() 

#    print(html)

    soup = BeautifulSoup(html,'html.parser')
#    print(soup)
    div = soup.select_one('#SHOW_TOPIC > div.balance > div.firstPostBox > div > div > div.postRightContent > div.postcontent > div.postBody')
    div.select_one('script').decompose() 

    postcontent = div.text.strip()
    postcontent = re.sub(r'\n+', ' ',postcontent)
    print(postcontent)

crawlcontents()

This is crawling in trip site

I need script but, the error is "python 'NoneType' object has no attribute 'decompose'"

how do i change?




Aucun commentaire:

Enregistrer un commentaire