【发布时间】:2021-05-02 00:02:37
【问题描述】:
我尝试抓取 website。但我未能提取每个项目的描述。这是我的代码:
from bs4 import BeautifulSoup
import requests
url = "http://engine.ddtc.co.id/putusan-pengadilan-pajak"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data, 'html.parser')
puts =soup.find_all("div",{"class":"p3-search-item"})
for put in puts:
title = put.find("div", {"class":"p3-title"}).text
cat = put.find("div", {"class":"p3-category"}).text
date = put.find("div", {"class":"search-result-item-meta"}).text
link = put.find("a").get("href")
put_response = requests.get(link)
put_data = put_response.text
put_soup = BeautifulSoup(put_data, "html.parser")
put_description = put_soup.find("div",{"id": "modal-contents-pp"}).text
print("Judul Putusan:", title, "\nKategori:", cat, "\nTanggal:", date, "\nLink:", link, "\nDescription:", put_description)
所以我未能提取描述。 描述只显示空白和几个单词。如果我们单击每个项目的链接,则可以显示完整的描述。 非常感谢任何帮助。
【问题讨论】:
-
似乎链接打开了通过 javascript 加载的页面,因此您需要一个可以执行 javascript 的解决方案。在 StackOverflow 中搜索 Selenium。
-
但我不明白,当我检查网页时,它显然包含 div 等,我看不出它是否使用 javascript
标签: python web-scraping beautifulsoup