Python-urllib在firefox中的不同结果

2024-04-19 08:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图为一家奥地利报纸的留言板编写一个webcrawler程序derstandard.at公司. 我对交互感兴趣,我想对用户进行网络分析。 我能够检索到我想要的一切,但当涉及到改变留言板页面它根本不起作用。你知道吗

使用firefox,我可以通过改变url中的一个数字来访问我想要的页面,例如第5页

http://derstandard.at/1345164506806/Umfrage-FPOe-auf-tiefstem-Stand-seit-mehr-als-zwei-Jahren?seite=5#forumstart

当我试图从我的python脚本中访问它时,我总是得到第1页。你知道吗

首先,我认为这是因为我的用户代理,但我把它改为我的firefox用户代理,仍然得到所有的方式第1页。为什么会这样?你知道吗

以下是相关代码段:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib
from BeautifulSoup import BeautifulSoup

from urllib import FancyURLopener
class MyOpener(FancyURLopener):
    version = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:14.0) Gecko/20100101 Firefox/14.0.1'

f_open=MyOpener()

page=BeautifulSoup(f_open.open('http://derstandard.at/1345164506806/Umfrage-FPOe-auf-tiefstem-Stand-seit-mehr-als-zwei-Jahren?seite=5#forumstart'))

打印页


Tags: 用户importhttp页面openfirefoxatbeautifulsoup
1条回答
网友
1楼 · 发布于 2024-04-19 08:29:29

我对他的评论解决了这个问题。你知道吗

我的意见:

maybe it is the "#" i heard it can cause errors sometimes, put a r at the start of your search string. like r'http://derstandard.at/1345164506806/Umfrage-FPOe-auf-tiefstem-Stand-seit-mehr‌​-als-zwei-Jahren?seite=5#forumstart'

所以这似乎是一个简单的错误。你知道吗

相关问题 更多 >