logo
Loading...

如何爬蝦皮網站內容? - Cupoy

透過下列的方法迴回傳都是0,但是服務都是200是成功的,無法抓到我想要的值,但是透過瀏覽器的程式模式...

如何爬蝦皮網站內容?

2020/01/01 11:37 PM
Python網路爬蟲論壇
張庭耀
觀看數:0
回答數:1
收藏數:0

透過下列的方法迴回傳都是0,但是服務都是200是成功的,無法抓到我想要的值,但是透過瀏覽器的程式模式都看得到,求解,感謝。


import requests

import re

import pandas as pd

from bs4 import BeautifulSoup

from fake_useragent import UserAgent

import json


url = 'https://shopee.tw/shop/1819984/search?shopCollection=9271157'

headers = {

'Host': 'shopee.tw',

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0',

'Cookie':'SPC_IA=-1; SPC_EC=-; SPC_F=L07IMDECRHjifEKyg7XuNCJ00GNdJGTA; REC_T_ID=246cfcdc-18fa-11ea-b254-f8f21e2be0b8; SPC_T_ID="Fyr1skVDq7FDiJOuTYHBmMfMr2Cw1eZyPbYJhBYoRmf/gvfvkOf5zgjIVXLrYYlg32aSx1PfmhWq7QsQzwM86mdeXG8VU7ERK4N+gfPFd14="; SPC_U=-; SPC_T_IV="/oJN8EB7iQwg7+n5mXd6cw=="; _gcl_au=1.1.788704691.1575727322; _fbp=fb.1.1575727322914.443117835; _ga=GA1.2.1422761069.1575727324; __BWfp=c1575727332595xf5a099d8b; cto_lwid=7ea874b3-f31f-47d7-aef9-60eed0156d33; cto_bundle=0tgQ7V9rU3JlRTU4aWlTc09JNXRaN014Y3ZXa1BtVVcwT2RhOU1UZ0tweUFvWUo2WHRPQjd0JTJCM1duaG5iWXFFRWxpbHZkTFluWUZLSEFudTFreGJueFoxU0EyanhnMWN6ZEVIUVV6cFlhd050emhFMWQ4bmhVelZwVSUyRmwwQUp5c29lOEhPT2ZobE10S1dvT09HYWNhVXV1YWx5R3dSOGw0MHcwZWpiZ2pXU2VHSzdrJTNE; _med=refer; G_ENABLED_IDPS=google; fbm_382498665271383=base_domain=.shopee.tw; SPC_SI=jq6hwq6ju6hig9hfulumcagdqaiopatc; _gid=GA1.2.143857303.1577796150; csrftoken=3Pya3o5WYEvhLOj9FqCqbV3angfwBlko; AMP_TOKEN=%24NOT_FOUND; _dc_gtm_UA-61915057-6=1'

}


r = requests.get(url,headers=headers,allow_redirects=True)

print(r.status_code)

print(r.history)

print(r.url)


soup = BeautifulSoup(r.text, 'html.parser')

items = soup.find_all("div", class_="col-xs-2-4 shopee-search-item-result__item")

print(len(items))