您可以为此目的使用Selenium。它将像浏览器一样在运行时呈现您的网页。您可以将Selenium与firefox,chrome或phantomjs一起使用。
硒
由于大多数站点都是由现代Javascript框架组成的,因此我们基本上使用硒来完全呈现我们的网页。通常,它用于开发爬网程序/爬网程序以从网站的不同页面收集数据,或者Selenium也用于网络自动化。
有关Selenium的更多信息,请在此处阅读:http:
//selenium-
python.readthedocs.io/另外,我还为初学者撰写了有关Slenium的博客文章。也检查一下这个http://blog.hassanmehmood.com/creating-
your-first-crawler-in-python/
例
import urllibfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysprofile_link = 'http://hassanmehmood.com'class TitleScrapper(object): def __init__(self): fp = webdriver.FirefoxProfile() fp.set_preference("browser.startup.homepage_override.mstone", "ignore") #Avoid startup screen fp.set_preference("startup.homepage_welcome_url.additional", "about:blank") self.driver = webdriver.Firefox(firefox_profile=fp) self.driver.set_window_size(1120, 550) def scrape_profile(self): self.driver.get(profile_link) print self.driver.title self.driver.close() def scrape(self): self.scrape_profile()if __name__ == '__main__': scraper = TitleScrapper() scraper.scrape()


