-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