diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Allisan\345\207\257/week4/20210124.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Allisan\345\207\257/week4/20210124.py" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Allisan\345\207\257/week9/9-1.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Allisan\345\207\257/week9/9-1.py" new file mode 100644 index 0000000000000000000000000000000000000000..bf2fa5f3e9167f7a4ba92a308458c4e1a28c74cb --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_Allisan\345\207\257/week9/9-1.py" @@ -0,0 +1,61 @@ +import requests + +# 搜索页面访问 +def request_jd(keyword): + url = 'https://search.jd.com/Search' + headers = { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' + } + params = { + 'keyword': keyword + } + response = requests.get(url=url,headers=headers,params=params) + print(response.text) + + file_name = keyword+ '_jd.html' + with open(file_name,'w',encoding='utf-8') as f: + f.write(response.text) + +if __name__ == '__main__': + #request_jd('打火机') + names = ['袜子', '橘子'] + for name in names: + request_jd(name) + + +#详情页面访问 +def product_item(num): + url = 'https://item.jd.com/' + str(num) + headers = { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' + } + response_product = requests.get(url=url,params=None,headers=headers) + return response_product.text + +watermalon_num = product_item(10024683272181) + +with open('../../../../../pythonWork/pythonProject5/Lib/watermalon.html', 'w', encoding ='utf-8') as watermalon: + watermalon.write(watermalon_num) + + +#python 与json 数据的转换 +#json.dumps(): 对数据进行编码。 +#json.loads(): 对数据进行解码。 + +''' +json -> json.loads(值) -> python +python -> json.dumps(值) -> json + +python 中字典和json 的区别 +''' + + +import json +test_dict = { + 'a':1, + 'b': ['1',2,None], + 'c': {'d':1} +} +json_data = json.dumps(test_dict) +print(json_data) +print(json.loads(json_data)) \ No newline at end of file