【问题标题】:Why Machenize package in Python opens the support page when I try to open Google AdWords?为什么当我尝试打开 Google AdWords 时,Python 中的 Machenize 包会打开支持页面?
【发布时间】:2015-03-10 22:10:41
【问题描述】:

我使用 Machenize 打开 google AdWord 页面,但它重定向到支持页面,请参阅下面的代码。:

br = mechanize.Browser()
br.set_handle_robots(False)  
br.set_handle_refresh(False)  

url="https://accounts.google.com/ServiceLogin"
br.open(url)
br.form = list(br.forms())[0]

email = "myEmail"
password = "myPassword"

br.form["Email"] = email 
br.form["Passwd"] = password

response=br.submit() # And submit ! so far its ok, now Im in right page

br.open("https://adwords.google.com/") # The problem is here, the browser doesnt open this page
print br.geturl() # It opens this page : https://support.google.com/adwords/answer/1704376?hl=en#browsersupport

我无法进入 AdWords 页面,登录后我只能看到支持页面,为什么> 提前致谢。

【问题讨论】:

    标签: python python-2.7 url web-scraping google-ads-api


    【解决方案1】:

    在使用不受支持的浏览器时,AdWords 会重定向到此支持页面。

    你应该可以通过伪装你的用户代理来解决这个问题。

    【讨论】:

    • 非常感谢@Florianlh。没错,在使用以下代码伪造代理后,它可以完美运行: opener.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/ 17.0.963.56 Safari/535.11'), ('接受', 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8'), (' Accept-Encoding', 'gzip,deflate,sdch'), ('Accept-Language', 'en-US,en;q=0.8'), ('Accept-Charset', 'ISO-8859-1,utf- 8;q=0.7,*;q=0.3')] ]
    • 好的,很高兴看到这解决了您的问题。那么,您能否将我的答案标记为已接受?
    猜你喜欢
    • 2022-08-07
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多