Aduirrrr
2021-08-16 16:57
采纳率: 100%
浏览 50
已结题

Python 爬中文页面但爬到的是英文 附码

import requests
from bs4 import BeautifulSoup
import pandas

headers = {
    'cookie' : 'CGIC=IocBdGV4dC9odG1sLGFwcGxpY2F0aW9uL3hodG1sK3htbCxhcHBsaWNhdGlvbi94bWw7cT0wLjksaW1hZ2UvYXZpZixpbWFnZS93ZWJwLGltYWdlL2FwbmcsKi8qO3E9MC44LGFwcGxpY2F0aW9uL3NpZ25lZC1leGNoYW5nZTt2PWIzO3E9MC45; CONSENT=YES+TW.zh-TW+20170430-09-0; googtrans=/auto/zh-TW; __Secure-HSID=Aqti3_ARoiWh1al3W; __Secure-SSID=A3yBY2FfrkwZu1fpf; __Secure-APISID=hSDWbsylZB16B2Ft/ANjkGt5_I2m4RVsgj; S=adwords-usermgmt=WyGUBem9A7zZFab8zXYoKm8NaxCZm0VAyXzQeidxIDc:adwords-frontend-reporting=M3Dtwrd21TsB2oyhMyAXI-Gv0OJGADFQ:adwords-frontend-mcc=nsCGJtL-PX29IArzkQZDiq98zMsFMUw2:adwords-navi=PiwqC-qz5umFvX7ZonqyrKovuNy82tWE:adwords-campaignmgmt=y8lAr-PpXZ6Gc0pMNyXdAo815F_kD2Sh:adwords-frontend-displayads=Xu5fC_AqRFUSjQ_ItcIkdUpzOTbMuz61:adwords-frontend-usermgmt=EL-XDmdQ1c3LCJsPAYxGaHVBXU4F2Ag_:billing-ui-v3=joBK9uTaOxO8jdas_oKpdIyMUzJTu5lk:billing-ui-v3-efe=joBK9uTaOxO8jdas_oKpdIyMUzJTu5lk:adwords-frontend-changehistory=RQIzy5fdKuNSe7_OgYpAr1E-hETejKES:adwords-frontend-bulk=7Gwqj5zVHYGDXf8WpXXRgQOOyNjnP6Rn; HSID=AsUEZM6Q7pOKaQzws; SSID=AgViqTtgiqeWpOzmH; APISID=8EGBMha9ylPvz4qO/AsDTddlps3HWxaGyQ; SAPISID=CTMqCSbQo8CVBTXp/AZedmbuLopKdiXHgi; __Secure-1PAPISID=CTMqCSbQo8CVBTXp/AZedmbuLopKdiXHgi; __Secure-3PAPISID=CTMqCSbQo8CVBTXp/AZedmbuLopKdiXHgi; SID=AQiJD6NPmXIKdubxDJGB_KGCljemRjbS3Hi26qak2nJEtDMn3U-P2FADldzF3JnnQ8uqaA.; __Secure-3PSID=AQiJD6NPmXIKdubxDJGB_KGCljemRjbS3Hi26qak2nJEtDMnc2jIEwyAdoJYwLZCx9FePg.; __Secure-1PSID=AQiJD6NPmXIKdubxDJGB_KGCljemRjbS3Hi26qak2nJEtDMnsxaIqDJDYfMi3QBch1B6wg.; OTZ=6094327_24_24__24_; SEARCH_SAMESITE=CgQIppMB; NID=221=I4VbznydI4toonEkLgvdqQ6VNEtYzmQMtLxBfu59iXFcoAtccaCFppcHTb3wdFGFQ8BD3d51tenD1Ywe76eKXUt_yFdPm2h-PG5bUprkn9pgRbdmilXFj0nbdVjbfixi48YFH7iq_Mt7jEBXOUukccrNV513pGY01BZjBcAhEexub2oI3t9DRNSL307QV3pTvyGB9ixrP_YZxZISJvGb6IaF1i547PodzXaZAa5M9X8KupSMvgX9zN-wK5aTQhaXjXGZ3S6yOfui7ZNTITpNIobXfnyE3CK3mwb4lmLUdUzoJ7P-kqYEr7SGvXtilWVpXu6T_YpMATQZuah4gkknqR-dA8yvyeucxEM_88qJ_LhI4aKbWz3MEQjCtEV11VZJdtOs3RDs_ISj82mKvFECBHT6nrdDERtdKz7yFeBtST3_as-7tp7BcAY-5xl5LEiyLqMN-e3fqrRWR5ki2O56I-WFT7-F-bN3DzgBhg_TIHpmrJVH_amk8oHmaiOjZeZMYa4Q1g-lHCMRiO4FywcZtAr813GJirmNCta7x2E0BEG8XeeSGJMBV2esALWZWkd3-aqpmAeY8RfiPaNyiR25bxB-89yP2wUQt5ZUpVlzT8pOrujtPIC0HgXqRwCg7LrF6qVCTPG4eLUgVF6QvJkUAQsscAS7RXtqiA1dRrH3iCt4jg0; 1P_JAR=2021-08-16-04; SIDCC=AJi4QfGOSEj6tbWWRzXPT8EZdVat2JivAYcQCFDLYVgXiGoQj6GAs5C-PDWSEGZjEKPL89-Nd4XM; __Secure-3PSIDCC=AJi4QfEb_8eqP2uUofJZsDd5VJamddhhdzFWPSLmkZsns0WgiEXM9iGeSSg-4jACXHiKVG4lEKym',
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36',
    'Accept-Language':'zh-CN'
}
url = 'https://bbbeauty.com.hk/collections/sale?page=1'
s = requests.session()
res = s.get(url, headers=headers)
soup = BeautifulSoup(res.text, "html.parser")

result = soup.find_all('h3')
for i in range(len(result)) :
    print(result[i].getText())

img

要爬中文产品名称,但怎么爬都是英文

img

是否和网页右下角的中文英文切换有关?

img

有没有解决的方法可以分享,谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题