Skip to content Skip to sidebar Skip to footer

Python Beautifulsoup - Scrape Web Content Inside Iframes

We have this URL: https://www.aliexpress.com/store/feedback-score/1665279.html And the needed content is the 'Feedback History' table, which is inside an iframe: Feedback 1 Mon

Solution 1:

You just need to obtain the src attribute of the iframe, and then request and parse its content:

import requests
from bs4 import BeautifulSoup

s = requests.Session()
r = s.get("https://www.aliexpress.com/store/feedback-score/1665279.html")

soup = BeautifulSoup(r.content, "html.parser")
iframe_src = soup.select_one("#detail-displayer").attrs["src"]

r = s.get(f"https:{iframe_src}")

soup = BeautifulSoup(r.content, "html.parser")
for row in soup.select(".history-tb tr"):
    print("\t".join([e.textfor e in row.select("th, td")]))

Result:

Feedback        1 Month         3 Months        6 Months
Positive (4-5 Stars)    154     562     1,550
Neutral (3 Stars)       8       19      65
Negative (1-2 Stars)    8       20      57
Positive feedback rate  95.1%   96.6%   96.5%

Post a Comment for "Python Beautifulsoup - Scrape Web Content Inside Iframes"