我正在尝试从网站上抓取数据www.vestiairecollective.com
而抓取时我只能访问它的几个主页。例如,我的脚本无法抓取 url 的数据http://www.vestiairecollective.com/women-bags/handbags/#_=catalog&id_brand%5B%5D=50&material%5B%5D=3&step=180
。
我已经提到了许多关于堆栈溢出的问题,这些问题展示了如何做到这一点。当我在 Windows 上使用 python 3.5 时,“mechanize”和“cookielib”不起作用。我还看到一些问题指出像“robobrowser”这样的库可以完成这项工作。我也试过了,结果卡在了中间。
然后我尝试使用会话,当我使用 request.Sessions() 键入时,它说请求没有称为会话的属性。
当我使用上述 URL 时,请使用 robobrowser 或任何其他方式帮助我处理此特定网站的代码。
这是我在参考答案后尝试过的:-
import urllib.request
from bs4 import BeautifulSoup
import requests
session=requests.Session()
loginUrl='http://www.vestiairecollective.com/'
resLogin=session.post(loginUrl,data= {'h':'5fcdc0ac04537595a747e2830037cca0','email':'something@gmail.com','password':'somepasswrd','ga_client_id':'750706459.1463098234'})
url='http://www.vestiairecollective.com/women-bags/handbags/#_=catalog&id_brand%5B%5D=50&material%5B%5D=3'
res=session.get(url)
//The below url i have given because I want to scrape from this url
crl=urllib.request.urlopen("http://www.vestiairecollective.com/women-bags/handbags/#_=catalog&id_brand%5B%5D=50&material%5B%5D=3")
soup=BeautifulSoup(crl.read(),"html.parser")
geturl=soup.find_all("div",{"class":"expand-snippet-container"})
for i in geturl: //The Scraping Part
data1=i.find_all("p",{"class":"brand"})
datac1=[da.contents[0] for da in data1]
brdata=("\n".join(datac1))
print(brdata)
这里应该从“crl”页面进行抓取,但从主页本身进行。