【发布时间】:2018-01-31 03:03:27
【问题描述】:
我正在尝试从blog post 获取博客内容,我的意思是前六段。到目前为止,这是我想出的:
soup = BeautifulSoup(url, 'lxml')
body = soup.find('div', class_='post-body')
打印body 还会在主 div 标签下包含其他内容。
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup
我正在尝试从blog post 获取博客内容,我的意思是前六段。到目前为止,这是我想出的:
soup = BeautifulSoup(url, 'lxml')
body = soup.find('div', class_='post-body')
打印body 还会在主 div 标签下包含其他内容。
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup
试试这个:
import requests ; from bs4 import BeautifulSoup
res = requests.get("http://www.fashionpulis.com/2017/08/being-proud-too-soon.html").text
soup = BeautifulSoup(res, 'html.parser')
for item in soup.select("div#post-body-604825342214355274"):
print(item.text.strip())
使用这个:
import requests ; from bs4 import BeautifulSoup
res = requests.get("http://www.fashionpulis.com/2017/08/acceptance-is-must.html").text
soup = BeautifulSoup(res, 'html.parser')
for item in soup.select("div[id^='post-body-']"):
print(item.text)
【讨论】:
import re; soup.findAll('div', class_=re.compile('post-body'))。 BeautifulSoup 原生处理
我发现这个解决方案非常有趣:Scrape multiple pages with BeautifulSoup and Python
但是,我还没有找到任何要处理的查询字符串参数,也许你可以从这种方法开始。
我觉得现在最明显的事情是这样的:
【讨论】: