好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 xianrenzhang 于 2022-3-28 22:12 编辑
# 部分房产信息获取
# from requests_html import HTMLSession
# from bs4 import BeautifulSoup
#
# session = HTMLSession()
#
# url = ''
# headers = {
# 'user-agent': 'abc'}
# res = session.get(url=url, headers=headers).text
#
# soup = BeautifulSoup(res, 'lxml')
# page_info = soup.select('body > div.main1200.clearfix > div.main945.floatl > div.shop_list.shop_list_4 > dl')
# with open('./fangchan.csv', 'w') as f:
# info_fangchan = []
# for i in page_info:
# titles = i.select('dd:nth-child(2) > h4 > a')
# pric = i.select('dd.price_right > span.red > b')
# sim_pric = i.select('dd.price_right > span:nth-child(2)')
# for j in titles:
# # 删除前空格和后空行
# tits = j.text.lstrip().strip('\n') + '\n'
# info_fangchan.append(tits)
# url拼接
# urls = 'https://abc' + j.attrs['href'] + '\n'
# info_fangchan.append(urls)
# for h1 in sim_pric:
# h3 = '单价:' + h1.text + '\n'
# info_fangchan.append(h3)
# for k2 in pric:
# k3 = '总价:' + k2.text + '万元' + '\r\n'
# info_fangchan.append(k3)
# for all_info in info_fangchan:
# f.write(all_info)
# print('下载完毕!!!') |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|