我需要从论坛的帖子中获取文本。 网站是这样的: http://forum.pcekspert.com/showthread.php?t=263544
我试着这样做:
import requests
from bs4 import BeautifulSoup
# Create a variable with the url
url = 'http://forum.pcekspert.com/showthread.php?t=263544'
# Use requests to get the contents
r = requests.get(url)
# Get the text of the contents
html_content = r.text
# Convert the html content into a beautiful soup object
soup = BeautifulSoup(html_content,"lxml")
rez = soup.find_all('id=\"__xclaimwords_wrapper\"')
print(rez)
从文件的html中,我发现post消息有两个标记。你知道吗
文本第一个id中的xxx是一个7位数的数字,每条post消息都有一个不同的数字。你知道吗
您可以使用css select来查找具有
__xclaimwords_wrapper
id的dic并从中提取文本,即消息文本的位置:输出:
与你在页面上看到的相符。你知道吗
相关问题 更多 >
编程相关推荐