python 未知
2024-09-04 06:03:02
import time
import requests
from bs4 import BeautifulSoup
import threading def format_str(s):
return s.replace("\n","").replace("","").replace("\t",'') def get_urls_in_pages(from_page_num,to_page_num):
urls=[]
search_word='计算机'
url_part_1='http://www.phei.com.cn/moudle/goods/'\
'searchkey.jsp? Page='
url_part_2='&Page=2&searchKey='
for i in range(from_page_num,to_page_num+1):
urls.append(url_part_1
+str(i)+
url_part_2+search_word)
all_href_list=[]
for url in urls:
print(url)
resp=requests.get(url)
bs=BeautifulSoup(resp.text)
a_list=bs.find_all('a')
needed_list=[]
for a in a_list:
if 'href'in a.attrs:
href_val=a['href']
title=a.text
if 'bookid'in href_val and 'shopcar0.jsp'\
not in href_val and title !='':
if [title,href_val] not in needed_list:
needed_list.append([format_str(title),
format_str(href_val)])
all_href_list+=needed_list
all_href_file=open(str(from_page_num)+'_'+
str(to_page_num)+'_'+
'all_hrefs.txt','w')
for href in all_href_list:
all_href_file.write('\t'.join(href)+'\n')
all_href_file.close()
print(from_page_num,to_page_num,len(all_href_list))
最新文章
- HTML 基础篇
- Oracle中的CHR()函数与ASCII()函数
- 给HashMap排序,使之成为有序Map
- js操作Dom的一些方法简化
- Ideal-image-slider 幻灯片
- 先学习Oracle 11g的Automatic Diagnostic Repository新功能
- PAT (Advanced Level) 1011. World Cup Betting (20)
- 较简单的用ajax修改和添加功能(链接数据库)
- 摸索出来的chrom调试前后台数据(Java&;&;Ajax)交互的方法分享一下咯!!!
- Nginx配置文件及模块解析
- JVM简析
- sql数据库光标变成黑快怎么回事?
- 冲刺博客NO.10
- 把旧系统迁移到.Net Core 2.0 日记(8) - EASYUI datagrid+ Dapper+ 导出Excel
- 元组类型&;字典类型
- C#并行编程-PLINQ:声明式数据并行-转载
- 使用oracle导出的dmp文件(包含表结构还是表数据?)
- 在swift工程调用第三方库,Bridging导入头文件提示not found解决办法
- 如何得知 GIC 的所有中斷
- Linux Find Out Last System Reboot Time and Date Command 登录安全 开关机 记录 帐号审计 历史记录命令条数