假设您正试图从使用javascript模板(例如handlebars之类)呈现的页面获取值,那么这就是任何标准解决方案(即
beautifulsoup或
requests)所能获得的。
这是因为浏览器使用javascript更改了接收到的内容并创建了新的DOM元素。
urllib将像浏览器一样执行请求部分,而不是模板呈现部分。本文讨论了三种主要解决方案:
- 直接解析ajax JSON
- 使用离线Javascript解释器处理SpiderMonkey和Crowbar请求
- 使用浏览器自动化工具分解
编辑
从您的评论看来,它是一个由把手驱动的网站。这个答案给出了一个很好的代码示例,可能会有用:
from bs4 import BeautifulSoupfrom selenium import webdriverdriver = webdriver.Firefox()driver.get('http://eve-central.com/home/quicklook.html?typeid=34')html = driver.page_sourcesoup = BeautifulSoup(html)# check out the docs for the kinds of things you can do with 'find_all'# this (untested) snippet should find tags with a specific class ID# see: http://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-classfor tag in soup.find_all("a", class_="my_class"): print tag.text硒基本上是从您的浏览器获取呈现的HTML,然后您可以使用来自
page_source属性的BeautifulSoup对其进行解析。祝好运 :)



