Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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 beatifulsoup解析整个网站_Python_Web Scraping_Beautifulsoup_Scrapy - Fatal编程技术网

使用python beatifulsoup解析整个网站

使用python beatifulsoup解析整个网站,python,web-scraping,beautifulsoup,scrapy,Python,Web Scraping,Beautifulsoup,Scrapy,当我为了学习而尝试解析时。当我运行代码时,它只解析一个页面,我的意思是,主页 我如何解析整个网站,我的意思是,一个网站的所有页面 我尝试的代码如下所示: from bs4 import BeautifulSoup import re from urllib.request import urlopen html_page = urlopen("http://www.bdjobs.com/") soup = BeautifulSoup(html_page, "html.parser")

当我为了学习而尝试解析时。当我运行代码时,它只解析一个页面,我的意思是,主页

我如何解析整个网站,我的意思是,一个网站的所有页面

我尝试的代码如下所示:

from bs4 import BeautifulSoup
import re
from urllib.request import urlopen

html_page = urlopen("http://www.bdjobs.com/")

soup = BeautifulSoup(html_page, "html.parser")




# To Export to csv file, we used below code.

links = []
for link in soup.findAll('a', attrs={'href': re.compile("^http")}):
    links.append(link.get('href'))
import pandas as pd
df = pd.DataFrame(links)
df.to_csv('link.csv')

#print(df)

你能告诉我如何解析整个网站,而不是一个页面吗?

你有几个选择,这取决于你想要实现什么

编写自己的爬虫程序

与您试图在代码片段中执行的操作类似,从网站获取一个页面,识别该页面中所有感兴趣的链接(使用xpath、正则表达式等),然后迭代,直到您访问了整个域

这可能最适合学习爬行的基础知识,或者作为一次性任务快速获取一些信息

你必须小心一些想法,比如不要访问同一个链接两次,限制域名以避免访问其他网站等

使用网页抓取框架

如果您想执行一些严重的擦伤,对于生产应用程序或大规模的刮削,请考虑使用诸如./P>这样的框架。


它为您解决了许多常见的问题,通过阅读文档和深入了解代码,这是学习高级web抓取技术的好方法。

您需要对网站进行爬网以获取相关页面。这里有一个网站描述了如何使用webcrawler请求:哇!你想刮一百万页?