网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
def get_local_time_string():
“”"
返回形如"2021-04-09"这样的时间字符串
“”"
current = time.localtime()
return time.strftime(“%Y-%m-%d”, current)
价格等维度
def get_price_info(self, city_name):
self.city_name = city_name
self.price_info_list = list()
target_web = 'http://{0}.fang.ke.com/loupan/'.format(city_name)
print('request target web:', target_web)
# 获得请求头部
headers = create_request_headers()
# 发起网页请求(获取总页数)
response = requests.get(target_web, timeout=10, headers=headers)
html = response.content
soup = BeautifulSoup(html, 'lxml')
# 获得response总页数
try:
page_box = soup.find_all('div', class_='page-box')[0]
matches = re.search(r'.*data-total-count="(\d+)".*', str(page_box))
total_page = int(math.ceil(int(matches.group(1)) / 10))
# total_page = 2 测试
except Exception as e:
print("warning: only find one page for {0}".format(city_name))
print(e)
print('total pages:', total_page)
headers = create_request_headers()
# 遍历房价网页
# for i in range(1, total_page + 1) :
for i in range(1, total_page