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