import time
from selenium import webdriver
for num in range(1,11):#实现分页浏览
url = 'https://cq.fang.lianjia.com/loupan/nhs'+str(num)+'/'
print(url)
driver=webdriver.Chrome()
driver.get(url)
js='scrollTo(0,500)'
driver.execute_script(js)
lists=driver.find_elements_by_xpath('//div[@class="resblock-desc-wrapper"]')
fp=open('./链家.txt',"a",encoding="utf-8")
for list1 in lists:
temp={}
temp["title"]=list1.find_element_by_xpath('./div[@class="resblock-name"]/a').text
temp['location'] = list1.find_element_by_xpath('./div[@class="resblock-location"]/span').text
temp['price']=list1.find_element_by_xpath('./div[@class="resblock-price"]//span').text
print(temp)
fp.write(str(temp)+"\n")
driver.close()