【发布时间】:2020-07-21 19:59:21
【问题描述】:
如何获取在此URL 的 iframe 中找到的 PDF?
(1)以下代码抛出错误。
import requests, re
from bs4 import BeautifulSoup
url = r'https://www.d88a.org/domain/102'
headers = {'User-Agent': 'C19SchoolsWebscrape'}
s = requests.Session()
r = s.get(url, headers=headers)
soup = BeautifulSoup(r.content, "lxml")
iframe_src = soup.select_one("swGoogleDrive").attrs["src"]
r = s.get(f"https:{iframe_src}")
print(r)
error: 'NoneType' object has no attribute 'attrs'
(2) 这也会引发错误。
response = requests.get(url, headers=headers)
t = re.search(b'(?<=artist":")(.*?)(?=")', response.content).group(0).decode("utf-8")
print(t)
error: 'NoneType' object has no attribute 'group'
我之前引用过的线程: Python BeautifulSoup - Scrape Web Content Inside Iframes, extract iFrame content using BeautifulSoup
【问题讨论】:
标签: python-3.x iframe beautifulsoup lxml