当前位置:   article > 正文

爬取北京二手房数据信息(python)_爬虫二手房源码beautifulsoup

爬虫二手房源码beautifulsoup

数据爬取

爬取北京二手房数据信息python代码:

  1. # coding : utf-8
  2. from requests import get
  3. from bs4 import BeautifulSoup as bs
  4. from tqdm import tqdm
  5. from multiprocessing import Pool
  6. from time import time
  7. from os import listdir
  8. from csv import writer
  9. import re
  10. def url_spider(url):
  11. """
  12. 爬取网页信息
  13. """
  14. headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER'}
  15. try:
  16. response = get(url, headers=headers, verify=True, timeout=10)
  17. if response.status_code == 200:
  18. soup = bs(response.text, features="html.parser")
  19. return soup
  20. else:
  21. print("\n\n*** (%s)请求状态异常 ***\n\n" % url)
  22. return None # 状态码非200则返回空值
  23. except Exception as e:
  24. print('\n\n*** Requests.get(%s) gets wrong! ***\nThe program wil
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/212268
推荐阅读
相关标签
  

闽ICP备14008679号