Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.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 如何循环浏览嵌套网页以进行网页抓取?_Python_Beautifulsoup - Fatal编程技术网

Python 如何循环浏览嵌套网页以进行网页抓取?

Python 如何循环浏览嵌套网页以进行网页抓取?,python,beautifulsoup,Python,Beautifulsoup,我想从网页上删除数据 我计划从这个网站上获取每个公司的名称和位置。我想我需要以某种方式循环浏览每一页,但如果在另一页中,我不确定如何做到这一点 我只是稍微轻松地浏览了一页,所以任何形式的帮助都将不胜感激 你可以把你的刮削过程想象成一棵树,你可以沿着每一个页面的分支往下走。所以在一些粗略的伪代码中,它看起来像这样: company_details = {} request the landing page and parse for letter_href in land

我想从网页上删除数据

我计划从这个网站上获取每个公司的名称和位置。我想我需要以某种方式循环浏览每一页,但如果在另一页中,我不确定如何做到这一点


我只是稍微轻松地浏览了一页,所以任何形式的帮助都将不胜感激

你可以把你的刮削过程想象成一棵树,你可以沿着每一个页面的分支往下走。所以在一些粗略的伪代码中,它看起来像这样:

    company_details = {}
    request the landing page and parse
    for letter_href in landing_page:
        scrape the company_code URL and parse
        company_code = some_code_you_scraped
        for company_href in company_code_page:
            scrape the company page URL and parse
            append each company info to the company_details dictionary including the company_code you grabbed from the previous page.

希望这有帮助

好吧,从你能做的开始,抓取1页。然后尝试在点击页面的过程中循环。只是计划一下,你会怎么做?1) 从第一页获取所有链接。2) 反复浏览这些链接。3) 当您进行迭代时,您将如何从这些页面中获取所需的数据?4) 以某种方式存储数据,这样,当您继续迭代中的下一个链接时,数据将附加(并且不会覆盖)您从上一页获取的内容。从简单开始:从2页循环开始。然后,一旦它起作用,扩展/修饰它到更多