我嘗試做詞典循環。 例如將詞典值組合在一起
A = {"Name":1,"Price":2}
B = {"Name":3,"Price":6}
C = {"Name":"","Price":3}
我想補充A B和C一起
C = {"Name":[1,3,],"Price":[2,6,3]}
我怎樣才能做到這一點?謝謝 這是我實際的代碼我試圖抓住從住宿頁的數據。它仍然缺少將所有數據字典放在一起的部分,並循環下一頁,並再次感謝您的方式。
from bs4 import BeautifulSoup as soup
import re
from selenium import webdriver
driver = webdriver.Firefox()
my_url = 'https://www.hipflat.co.th/en/search/sale/condo_y/any_r1/any_r2/any_p/any_b/any_a/any_w/any_o/any_i/100.62442610451406,13.77183154691727_c/12_z/list_v'
driver.get(my_url)
html = driver.page_source
page_soup = soup(html)
#Grab Condo
Condo = page_soup.findAll("li",{"class":"listing"})
for Con in Condo:
Name = Con.findAll("div",{"class":"listing-project"})[0].text.strip()
Description = Con.p.text
Price = Con.findAll("div",{"class":"listing-price"})[0].text.strip()
Type = Con.findAll("ul",{"class":"listing-detail"})[0].text.replace("\n","")
Type = [Name]+[Price]+[Description]+re.split(r'(bed|bath|m2)',Type)
Data = {"Name" : Name,"Description" : Description,"Price":Price,"Bed":Type[3],"Bath":Type[5],"Area(m2)":Type[7],"Floor":Type[9]}
print(Data)
next_page = driver.find_element_by_xpath('//*[@id="page-content"]/div[2]/div/div[2]/div[1]/div[2]/div/div[3]/a[1]').click()
只有2,還是會有更多的字典? –
確定我猜編輯答案我 –
嗯,我該怎麼辦環路加入許多字典成一個 –