Python——爬取人口迁徙数据(以腾讯迁徙为例)
说明: 1.迁徙量是腾讯修改后的数值,无法确认真实性。 2.代码运行期间,腾讯迁徙未设置IP屏蔽和浏览器检测,因此下段代码仅能保证发布近期有效。 3.代码功能:爬取指定一天的四十(此四十是根据自己的城市列表而定,可多可少,并无限制)个城市左右的迁徙量(含迁入、迁出)。 1 import re 2 import urllib.request 3 import xlwt 4 import xlrd 5 6 date = " 20171016 " 7 cityList = xlrd.open_workbook( " E:/city.xls " ).sheet_by_index(0).col_values(0) # ['city', '南昌', '景德镇', '萍乡', ... 8 cityCodeList = xlrd.open_workbook( " E:/city.xls " ).sheet_by_index(0).col_values(1) # ['cityCode', '360100', '360200',... 9 direction = [ " 0 " , " 1 " ] 10 header = [ " from " , " to " , " number " , " car " , " train " , " plane " ] 11 dInd = 0 12 for