我正在打印这篇文章https://i.imgur.com/SLl1URt.png “我用过”汤。全部找到(“p”,class=“review”)”并尝试使用.getText或check-inside.contents,但都不起作用
网页链接https://m.wuxiaworld.co/Castle-of-Black-Iron/
下面是一些调试信息https://i.imgur.com/0k6NHeD.png
import urllib2
from bs4 import BeautifulSoup
def info(novelname):
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
url = "https://m.wuxiaworld.co/"+novelname+"/"
headers={'User-Agent':user_agent,'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
request = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(request)
soup = BeautifulSoup(response, features="html.parser")
for textp in soup.find_all("p", class_="review"):
print textp.contents
print textp
print textp.getText()
当你打印你的汤,你会看到一些html标签在终端(不是所有的源代码)。我认为网站隐藏了一部分数据。所以呢我建议使用硒。 如果您尚未下载,可以安装在:
所有代码:
输出:
问题是你的html解析器。。。使用html5lib
相关问题 更多 >
编程相关推荐