import requests
import pandas as pd
import csv
from bs4 import BeautifulSoup
from pandas import Series,DataFrame
import unicodecsv

def name1():
    url="https://www.agoda.com/zh-tw/pages/agoda/default/DestinationSearchResult.aspx?    asq=%2bZePx52sg5H8gZw3pGCybdmU7lFjoXS%2baxz%2bUoF4%2bbAw3oLIKgWQqUpZ91GacaGdIGlJ%2bfxiotUg7cHef4W8WIrREFyK%2bHWl%2ftRKlV7J5kUcPb7NK6DnLacMaVs1qlGagsx8liTdosF5by%2fmvF3ZvJvZqOWnEqFCm0staf3OvDRiEYy%2bVBJyLXucnzzqZp%2fcBP3%2bKCFNOTA%2br9ARInL665pxj%2fA%2bylTfAGs1qJCjm9nxgYafyEWBFMPjt2sg351B&city=18343&cid=1732641&tag=41460a09-3e65-d173-1233-629e2428d88e&gclid=Cj0KEQjwvve_BRDmg9Kt9ufO15EBEiQAKoc6qlyYthgdt9CgZ7a6g6yijP42n6DsCUSZXvtfEJdYqiAaAvdW8P8HAQ&tick=636119092231&isdym=true&searchterm=%E5%A2%BE%E4%B8%81&pagetypeid=1&origin=TW&cid=1732641&htmlLanguage=zh-tw&checkIn=2016-10-20&checkOut=2016-10-21&los=1&rooms=1&adults=2&children=0&isFromSearchBox=true&ckuid=1b070b17-86c2-4376-a4f5-d3b98fc9cf45" 

    source_code=requests.get(url)                                         

    plain_text=source_code.text                                           

    soup=BeautifulSoup(plain_text,"lxml")                                        

    for  a in soup.find_all("h3",{"class":"hotel-name"}):

        b=a.string.strip()
        print(b)

    csvfile=open('hotel.csv','w')
    wr=unicodecsv.writer(csvfile,encoding='utf-8')
    for item in b:
        wr.writerow(b)
    csvfile.close

name1()

I use python3 and win10 to write this code. I got problem to creat a csv file . I get data from web and store to variable b ,then I want to export the data in b to csv file but failed. Please help me .Thanks

If you look at https://docs.python.org/2/library/csv.html then you would see that your command argumentunicodecsv.writer() is odd... Also, next time when you ask this kind of question, please include what the ERROR you are getting. Saying "it failed" doesn't mean anything to any one. It sounds like you are an end user who tries to tell an IT support that "My computer doesn't work."

very thanks ,but sorry I'm new to here,and first time to ask question.I will pay more attention next time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.