当前位置:   article > 正文

python 爬虫-爬某家北京市各区二手房挂牌量_python 爬 挂牌量 数据

python 爬 挂牌量 数据
  1. import requests
  2. from bs4 import BeautifulSoup
  3. url = 'https://bj.lianjia.com/ershoufang'
  4. headers = {
  5. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
  6. res = requests.get(url, headers=headers)
  7. soup = BeautifulSoup(res.text, 'html.parser')
  8. districts = soup.select('.position dl:nth-of-type(2) dd div a')
  9. a = 0
  10. for district in districts:
  11. if a > 16:
  12. break
  13. district_name = district.text.strip()
  14. district_link = district['href']
  15. if 'ershoufang' in district_link:
  16. district_link = district_link.replace("ershoufang", '')
  17. district_link = url + district_link
  18. district_res = requests.get(district_link, headers=headers)
  19. district_soup = BeautifulSoup(district_res.text, 'html.parser')
  20. total = district_soup.select('#content > div.leftContent > div.resultDes.clear > h2 > span')[0].text
  21. print('{}: {}'.format(district_name, total))
  22. a = a + 1
  23. res = requests.get(url, headers=headers)
  24. soup = BeautifulSoup(res.text, 'html.parser')
  25. total = soup.select('#content > div.leftContent > div.resultDes.clear > h2 > span')[0].text
  26. print('{}: {}'.format('总量', total))

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/212275
推荐阅读
相关标签
  

闽ICP备14008679号