PhantomJS , selenium 使用过程无法渲染某些 js 页面,求各位大哥帮忙看看

2016-09-30 21:34:42 +08:00
 raingolee

利用 PhantomJS 去请求几个微博的 url ,发现没法渲染某个特定的 js 页面

以下为测试的伪代码,麻烦各位大哥可以帮忙看看


from selenium import webdriver
from selenium.webdriver import DesiredCapabilities

desired_capabilities \
= DesiredCapabilities.PHANTOMJS.copy()

desired_capabilities['phantomjs.page.customHeaders.User-Agent'] \
= headers['User-Agent']

desired_capabilities['phantomjs.page.customHeaders.Cookie'] = headers['Cookie']

driver = webdriver.PhantomJS(desired_capabilities=desired_capabilities)

driver.get(url)
htmlTag = driver.page_source

这时候我传了以下两个 url 进去,然后第二个 url 无论怎么请求返回的 html 都是没有渲染过的

#可以渲染
urlUser = 'http://weibo.com/sandra0314?refer_flag=1087030101_417'

#不能渲染
urlTag = 'http://d.weibo.com/1087030002_2975_2012_0#'

望得到大家帮助,谢谢

3234 次点击
所在节点    Python
3 条回复
BiggerLonger
2016-10-02 12:42:40 +08:00
吧#去掉試一下
raingolee
2016-10-02 17:27:03 +08:00
@BiggerLonger 好像可以了,啊啊啊,谢谢啊,困扰我好几天了
raingolee
2016-10-02 17:31:06 +08:00
@BiggerLonger 再试一次就不行了,呜呜呜

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/310073

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX