1. re.findall() 與 re.search()
????????測(cè)試代碼如下:
findall返回的是一個(gè)list洪乍,而search返回的是_sre.SRE_Match猾警。
print(urls):
['{\\"count\\":18,\\"sub_images\\":[{\\"url\\":\\"http:\\\\/\\\\/p1.pstatp.com\\\\/origin\\\\/2ebe000042c272cd8ca4\\",\\"width\\":650,\\"url_list\\":[{\\"url\\":\\"http:\\\\/\\\\/p1.pstatp.com\\\\/origin\\\\/2ebe000042c272cd8ca4\\"},{\\"url\\":\\"http:\\\\/\\\\/pb3.pstatp.com\\\\/origin\\\\/2ebe000042c272cd8ca4\\"},{\\"url\\":\\"http:\\\\/\\\\/pb9.pstatp.com\\\\/origin\\\\/2ebe000042c272cd8ca4\\"}],\\"uri\\":\\"origin\\\\/2ebe000042c272cd8ca4\\",\\"height\\":975},{...},...']? ? ? ? ? ? ? ? ? ? ? ? ? ? (為list)
print('urls1:',urls1):
urls1: <_sre.SRE_Match object; span=(4884, 12806), match='gallery: JSON.parse("{\\"count\\":18,\\"sub_image>
提取search中的信息用摩窃,urls1 = re.search(pattern,response.text).group(1)
print(urls1):
{\"count\":18,\"sub_images\":[{\"url\":\"http:\\/\\/p1.pstatp.com\\/origin\\/2ebe000042c272cd8ca4\",\"width\":650,\"url_list\":[{\"url\":\"http:\\/\\/p1.pstatp.com\\/origin\\/2ebe000042c272cd8ca4\"},{\"url\":\"http:\\/\\/pb3.pstatp.com\\/origin\\/2ebe000042c272cd8ca4\"},{\"url\":\"http:\\/\\/pb9.pstatp.com\\/origin\\/2ebe000042c272cd8ca4\"}],\"uri\":\"origin\\/2ebe000042c272cd8ca4\",\"height\":975},{...},...,}
print(type(urls1):
<class 'str'>
2.關(guān)于去掉'\':
使用replace方法:
replace的對(duì)象為str星立,若用的findall秸歧,需要使用 ",".join()拼接為用 “,”分割的str吕朵,再用replace
3.MongoDB的啟動(dòng)
使用home-brew安裝的凑兰,先用一下配置命令才能正常啟動(dòng)