-1
這個問題類似於被問到here的問題,但答案不是很有幫助。使用Python和美味湯提取Disqus評論
我想從使用Disqus的網頁中提取評論,但是我無法訪問該部分。
這是我迄今爲止,它沒有太多
import urllib
import urllib2,cookielib
from bs4 import BeautifulSoup
from IPython.display import HTML
site= "http://www.timesofmalta.com/articles/view/20161207/local/daphne-caruana-galizia-among-politicos-28-most-influential.633146"
hdr = {'User-Agent':'Mozilla/5.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page,"html.parser")
title = soup.title.text
print title
任何提示,我怎麼可能會試圖解決呢?
這取決於網頁。您嘗試使用JavaScript動態加載評論的網站,因此您無法使用urllib進行刮取,您需要使用類似Selenium的內容。 –
[用Python抓取JavaScript網頁]可能的重複(http://stackoverflow.com/questions/8049520/web-scraping-javascript-page-with-python) –