Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用嵌套框架和javascript进行Web抓取_Python_Beautifulsoup_Screen Scraping_Mechanize_Frames - Fatal编程技术网

Python 使用嵌套框架和javascript进行Web抓取

Python 使用嵌套框架和javascript进行Web抓取,python,beautifulsoup,screen-scraping,mechanize,frames,Python,Beautifulsoup,Screen Scraping,Mechanize,Frames,我想从在线聊天机器人那里得到答案。 ? (该?属于链接) 要发送问题,您只需发送一个简单的请求: http://talkingbox.dyndns.org:49495/in?id=3B9054BC032E53EF691A9A1803040F1C&msg=[Here the question] 来源如下: <frameset cols="*,185" frameborder="no" border="0" framespacing="0"> <frameset r

我想从在线聊天机器人那里得到答案。 ? (该?属于链接)

要发送问题,您只需发送一个简单的请求:

http://talkingbox.dyndns.org:49495/in?id=3B9054BC032E53EF691A9A1803040F1C&msg=[Here the question]
来源如下:

<frameset cols="*,185" frameborder="no" border="0" framespacing="0">
<frameset rows="100,*,82" frameborder="no" border="0" framespacing="0">
    <frame src="http://thebot.de/bt_banner.html" marginwidth="0" name="frtop" scrolling="no" marginheight="0" frameborder="no">
    <frame src="out?id=3B9054BC032E53EF691A9A1803040F1C" name="frout" marginwidth="0" marginheight="0">
    <frameset rows="100%,*" border="0" framespacing="0" frameborder="no">
        <frame src="bt_in?id=3B9054BC032E53EF691A9A1803040F1C" name="frin" scrolling="no" marginwidth="0" marginheight="0" noresize>
        <frame src="" name="frempty" marginwidth="0" marginheight="0" scrolling="auto" frameborder="no" >
    </frameset>
</frameset>
<frameset frameborder="no" border="0" framespacing="0" rows="82,*">
    <frame src="stats?" name="fr1" scrolling="no" marginwidth="0" marginheight="0" frameborder="no">
    <frame src="http://thebot.de/bt_rechts.html" name="fr2" scrolling="auto" marginwidth="0" marginheight="0" frameborder="no" >
</frameset>
</frameset>

我使用“mechanize”和beautifulsoup进行网页抓取,但我认为mechanize不支持动态网页

在这种情况下,我怎样才能得到答案

我也在寻找一个在Windows和Linux上运行良好的解决方案。

我会用它来完成这样的任务

import requests

r = requests.get("http://talkingbox.dyndns.org:49495/in?id=3B9054BC032E53EF691A9A1803040F1C&msg=" + your_question)
对于不包含动态内容的网页,
r.text
是您想要的


由于您没有提供有关动态网页的更多信息,因此没有更多信息要说。

无论是美化、机械化、请求,甚至是碎片化,加载动态网页都必须通过您编写的另一个步骤来完成

例如,使用scrapy,这可能看起来像:

class TheBotSpider(BaseSpider):
    name = 'thebot'
    allowed_domains = ['thebot.de', 'talkingbox.dyndns.org']

    def __init__(self, *a, **kw):
        super(TheBotSpider, self).__init__(*a, **kw)
        self.domain = 'http://talkingbox.dyndns.org:49495/'
        self.start_urls = [self.domain + 
                           'in?id=3B9054BC032E53EF691A9A1803040F1C&msg=' + 
                           self.question]

    def parse(self, response):
        sel = Selector(response)
        url = sel.xpath('//frame[@name="frout"]/@src').extract()[0]
        yield Request(url=url, callback=dynamic_page)

    def dynamic_page(self, response):
        .... xpath to scrape answer
以问题作为参数运行它:

scrapy crawl thebot -a question=[Here the question]

有关如何使用scrapy的更多详细信息,请参见

,您可以尝试selenuim,它擅长浏览器自动化以及phantomjs绑定(它为headless Webkit提供JS API,Webkit是一个渲染引擎)。什么是动态网页?这些框架只知道http请求,而且您共享的链接是inaccessible@Guy我认为“user317”指的是通过XHR请求获取的内容,但我同意更多细节会有所帮助。对不起,链接是?(末端的?被stackoverflow切断)。框架的Url是问题所在,不知何故框架无法像这样访问。感谢您的帮助。我可能需要澄清的是,我在获取答案而不是发送答案时遇到了问题,因为答案是在一个嵌套的框架内生成的,该框架是用JavaScript动态生成的。此框架: