作业
列出网络爬虫的步骤
选取具有代表性的部分网址作为种子URL。
将这些种子URL放入待抓取URL队列,打开开发者模式
从待抓取URL队列中取出其他的待抓取的URL,经过解析得到对应的主机的IP,然后将该地址对应的网页下载下来,存储到已下载网页库中。
把这些已经抓取过网页的URL放进已抓取URL队列。
分析已抓取URL队列中的URL,分析其中含有的其他URL地址,并且将这些URL地址放入待抓取URL队列。
返回步骤3,重复进行步骤3、4,直到待抓取URL队列为空,或者满足设置的其他结束条件。
列出爬虫实践的过程和结果,同时贴图
写出本次实践的心得体会和问题
通过这次Python实训,我收获了很多,一方面学习到了许多以前没学过的专业知识与知识的应用,
另一方面还提高了自我动手做项目的潜力。本次实训是对我潜力的进一步锻炼,也是一种考验。
从中获得的诸多收获,获得成功的快快感,体会到爬虫的乐趣,也是很可贵的,是十分有好处的。
列出爬虫实践的过程和结果,同时贴图
Request URL: https://www.ptpress.com.cn/hotBook/getHotBookList?parentTagId=75424c57-6dd7-4d1f-b6b9-8e95773c0593&rows=18&page=1
Request Method: GET
Status Code: 200
Remote Address: 39.96.127.170:443
Referrer Policy: strict-origin-when-cross-origin
爬取图书
#!/usrweilie/bin/python
#coding=utf-8
import re
import urllib
def gethtml(url): #获取网页html
jiuaoopage=urllib.urlopen(url)
html=jiuaoopage.read()
return html
def getstr(html): #利用正则表达式抓取‘联系我们’链接
r=r'<a href="(.*)" >联系我们' #正则表达式
fo=re.compile(r)
str1=fo.findall(html)
return str1
def gettel(html): #利用正则表达式抓取电话号码
r=r'\d{3}\-\d{8}'
fo=re.compile(r)
tel=fo.findall(html)
print(tel)
html=gethtml('http://www.jiuaoo.com/')
str1=getstr(html)
str2='http://www.jiuaoo.com'
for i in str1:
urlstr=str2+i
html=gethtml(urlstr)
gettel(html)
便利循环每一页
输入几页到几页
代码
import requests
import json
import time
#文件
f1 = open('hotbook.csv', 'w', encoding='utf-8')
content = '热销书名' + ',' + '价格' + '\n'
f1.write(content)
count_ = 0
#页
for page in range(2, 18): #
url = f'http://www.ptpress.com.cn/hotBook/getHotBookList?rows=18&page={page}'
return_data = requests.get(url).text
data = json.loads(return_data)
news = data['data']['rows']
for n in news:#行
bookName = n["bookName"]
price = n["price"]
count_ += 1
print("热销书名:", bookName, '\n', "书价:", price)
content = bookName + ',' + str(price) + '\n'
f1.write(content)
time.sleep(1)#休眠
print("共找到%d本畅销书" % count_)#输出
f1.close()
三孩子政策
8054

被折叠的 条评论
为什么被折叠?



