以下是一個簡單的程序,用于訪問1688店鋪并獲取店鋪信息:
import requestsdef get_store_info(store_id):# 構建請求URLurl = f'https://detail.1688.com/offer/{store_id}.html'# 發送GET請求response = requests.get(url)# 如果請求成功if response.status_code == 200:# 解析HTML內容,獲取店鋪信息store_info = parse_store_info(response.text)return store_infoelse:print('訪問店鋪失敗')def parse_store_info(html):# 進行解析,提取店鋪信息# 這里可以使用一些HTML解析庫,如BeautifulSoup或lxml等# 假設從HTML中解析出店鋪名和銷量store_name = '某某店鋪'sales_volume = '1000+'# 構建店鋪信息字典store_info = {'店鋪名': store_name,'銷量': sales_volume}return store_info# 使用示例
store_id = '123456789' # 店鋪ID,根據實際情況填寫
store_info = get_store_info(store_id)
print(store_info)
以上程序中,首先定義了一個get_store_info
函數,用于發送GET請求并獲取1688店鋪頁面的HTML內容。然后,定義了一個parse_store_info
函數,用于解析HTML內容,提取店鋪信息。最后,程序通過調用這兩個函數,實現了訪問1688店鋪并獲取店鋪信息的功能。