-1
我想從這個網頁廢數據:https://www.landefeld.de/gruppe/en/straight-screwed-connection-metric-/GE4LLMBeautifulSoup webscraping負載更多的從阿賈克斯的JSON數據
我跟着某些線程像這樣:BeautifulSoup subpages of list with "load more" pagination,但我沒有FINT正確的答案。
我想要爲所有項目(例如,所有的118不僅在第20位
我迄今爲止代碼:
import requests
import pandas
from bs4 import BeautifulSoup
r=requests.get("https://www.landefeld.de/gruppe/en/straight-screwed-connection-metric-/GE4LLM")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class","article-container"})
l=[]
for item in all:
d={}
d["Artikel"]=item.find("a",{"class","article-number"}).text.strip()
d["Bezeichnung"]=item.find("a",{"class","article-name"}).text.strip()
d["Bild"]="http://landefeld.de" + item.find("img",{"class","article-image"})['src'].strip()
try:
d["Material"]=item.find("p",{"class","material"}).text.strip()
except:
pass
props=item.find_all("p",{"class","property"})
val=item.find_all("p",{"class","value"})
for p, v in zip(props,val):
d[p.text]=v.text
l.append(d)
df=pandas.DataFrame(l)
df.to_excel("Output.xlsx")
我發現這個JavaScript代碼來源:
// Ersetzt die angezeigte Artikelliste durch eine neue, per Ajax geholte
Shop.Artikelliste.prototype.reload = function(callback) {
this.artikelAngezeigt = 0;
this._doAjaxRequest(callback);
};
// Ergaenzt die bestehende Artikelliste mit einer weiteren, per Ajax geholten
Shop.Artikelliste.prototype.loadMore = function(callback) {
$('.js-artikelliste-nachladebutton').addClass('is-loading');
this._doAjaxRequest(callback);
};
// Fuehrt den Ajax-Request aus, uebergibt die callback-Funktion
// an den Handler fuer das Ajax-Ergebnis.
Shop.Artikelliste.prototype._doAjaxRequest = function(callback) {
var request = $.extend({ 'param_1': this.artikelAngezeigt }, this.requestParams);
var _this = this; // Closure
Shop.Util.ajaxRequest(request, 1, function(error, result) {
_this._handleResult(error, result, callback);
$('.js-artikelliste-nachladebutton').removeClass('is-loading');
});
}
// Laedt die Seite ganz neu
// (Muss auch nach POST Requests funktionieren)
Shop.Artikelliste.prototype._doPageRequest = function() {
var params = [];
for (var key in this.requestParams) {
params.push(key + '=' + this.requestParams[key]);
}
var queryString = params.join(';');
var href = window.location.href;
var i = href.indexOf('?');
if (i == -1) {
href += '?' + queryString;
} else {
href = href.substring(0, i + 1) + queryString;
}
window.location.href = href;
}
// Wird mit dem Ergebnis vom Ajax-Request aufgerufen. Fuehrt zunaechst
// den callback aus, danach wird die Artikelliste ueberschrieben oder ergaenzt,
// danach der Nachladebutton aktualisiert und ggfalls ausgeblendet.
Shop.Artikelliste.prototype._handleResult = function(error, result, callback) {
if (error) { return; }
if (typeof callback === "function") {
callback(result);
}
if (this.artikelAngezeigt == 0) {
this.$container.html(result.html)
} else {
this.$container.append(result.html)
}
this.artikelAngezeigt = this.artikelAngezeigt + parseInt(result.count);
沒有人有我一個解決方案嗎?
感謝您的幫助
這不是一個問題。 –
你有什麼問題?您可以顯示您的代碼並指定您需要的內容。 –
@MrSam抱歉,不,我編輯我的問題... – knuspertante