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))

最新文章

  1. HTML 基础篇
  2. Oracle中的CHR()函数与ASCII()函数
  3. 给HashMap排序,使之成为有序Map
  4. js操作Dom的一些方法简化
  5. Ideal-image-slider 幻灯片
  6. 先学习Oracle 11g的Automatic Diagnostic Repository新功能
  7. PAT (Advanced Level) 1011. World Cup Betting (20)
  8. 较简单的用ajax修改和添加功能(链接数据库)
  9. 摸索出来的chrom调试前后台数据(Java&&Ajax)交互的方法分享一下咯!!!
  10. Nginx配置文件及模块解析
  11. JVM简析
  12. sql数据库光标变成黑快怎么回事?
  13. 冲刺博客NO.10
  14. 把旧系统迁移到.Net Core 2.0 日记(8) - EASYUI datagrid+ Dapper+ 导出Excel
  15. 元组类型&字典类型
  16. C#并行编程-PLINQ:声明式数据并行-转载
  17. 使用oracle导出的dmp文件(包含表结构还是表数据?)
  18. 在swift工程调用第三方库,Bridging导入头文件提示not found解决办法
  19. 如何得知 GIC 的所有中斷
  20. Linux Find Out Last System Reboot Time and Date Command 登录安全 开关机 记录 帐号审计 历史记录命令条数

热门文章

  1. codeforce 1073E. Segment Sum
  2. ubuntu16.04下配置静态ip
  3. Bing Maps进阶系列三:使用地图图像服务(ImageryService)
  4. js的时间展示
  5. AcWing算法基础1.3
  6. Jmeter jdbc连接
  7. tp5.0分页样式调控
  8. Leetcode0006--ZigZag Conversion
  9. 查看Windows XP是否已激活的方法
  10. 重绘DataGridView标头