Skip to content

Commit 483b6f9

Browse files
committed
新增58同城城市列表获取
1 parent 873ec92 commit 483b6f9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

fuck/58.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# encoding: utf-8
2+
__author__ = 'zhanghe'
3+
4+
5+
import requests
6+
import re
7+
import json
8+
9+
# 入口页的url
10+
url = 'http://www.58.com/changecity.aspx'
11+
12+
# 伪装成浏览器
13+
header = {
14+
'Host': 'www.58.com',
15+
'Referer': 'http://sh.58.com/',
16+
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36'
17+
}
18+
19+
s = requests.session()
20+
21+
22+
def get_city_list():
23+
"""
24+
获取城市列表
25+
"""
26+
response = s.get(url, headers=header)
27+
html = response.text
28+
rule = '<a href="http://.*?.58.com/" onclick="co\(\'(.*?)\'\)">(.*?)</a>'
29+
city_list = re.compile(rule, re.S).findall(html)
30+
city = {}
31+
for item in city_list:
32+
city[item[0]] = item[1]
33+
print json.dumps(city, indent=4).decode('raw_unicode_escape')
34+
35+
36+
if __name__ == '__main__':
37+
get_city_list()

0 commit comments

Comments
 (0)