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

python 未知的更多相关文章

  1. python未知网卡名情况下获取本机IP

    import socket def get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even ...

  2. ######【Python】【基础知识】【一些未知的知识点】######

    在查资料.看书过程中遇到的一些未知的领域.知识点: 1.模仿静态变量 可参考: https://www.runoob.com/python/python-exercise-example41.html ...

  3. 在python学习时间过程中,你会不断发现需要解决的问题,更多需要连接未知,这时候到哪里去查阅资料呢?

    1.safari online book https://www.safaribooksonline.com 知乎上有人问,送程序员什么礼物好,其中一个答案就是safari online.编程的英文书 ...

  4. python了解未知函数的方法

    ?func 如图:

  5. Python标准模块--Unicode

    1 模块简介 Python 3中最大的变化之一就是删除了Unicode类型.在Python 2中,有str类型和unicode类型,例如, Python 2.7.6 (default, Oct 26 ...

  6. 字符型图片验证码识别完整过程及Python实现

    字符型图片验证码识别完整过程及Python实现 1   摘要 验证码是目前互联网上非常常见也是非常重要的一个事物,充当着很多系统的 防火墙 功能,但是随时OCR技术的发展,验证码暴露出来的安全问题也越 ...

  7. 利用Python进行数据分析(2) 尝试处理一份JSON数据并生成条形图

    一.JSON 数据准备 首先准备一份 JSON 数据,这份数据共有 3560 条内容,每条内容结构如下: 本示例主要是以 tz(timezone 时区) 这一字段的值,分析这份数据里时区的分布情况. ...

  8. Windows下Python中pip安装Pillow报错总结(转载)

    遇到的俩种错误1.ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting 问题原因 ...

  9. 1 python大数据挖掘系列之基础知识入门

    preface Python在大数据行业非常火爆近两年,as a pythonic,所以也得涉足下大数据分析,下面就聊聊它们. Python数据分析与挖掘技术概述 所谓数据分析,即对已知的数据进行分析 ...

随机推荐

  1. Android:解决Gradle DSL method not found: 'runProguard()' 问题

    将Android Studio升级至最新版(1.0 RC 4)之后,运行项目时出现问题: Gradle DSL method not found: 'runProguard()' 从字面就能看出来,出 ...

  2. Android中关于横竖屏问题

    一.屏幕的方向可以在AndroidManifest.xml文件中通过设置screenOrientation属性来实现, screenOrientation用来指定Activity的在设备上显示的方向, ...

  3. MODULE_DEVICE_TABLE的理解【转】

    本文转载自:http://blog.csdn.net/sidely/article/details/39666471 在Linux IIC驱动中看到一段代码: static struct platfo ...

  4. luogu 3383【模板】线性筛素数

    我太菜了 %韩神 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib&g ...

  5. P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 状压dp

    这个状压dp其实很明显,n < 18写在前面了当然是状压.状态其实也很好想,但是有点问题,就是如何判断空间是否够大. 再单开一个g数组,存剩余空间就行了. 题干: 题目描述 A little k ...

  6. Android SDK Manager 无法更新问题(转载)

    先看看如何加快更新速度,再说如何更新. 首先更新host文件,如图,打开目录 C:\Windows\System32\drivers\etc,在目录下有hosts文件 打开方式选用“记事本”打开 将一 ...

  7. 编译android4.4 报错error: call to '__property_get_too_small_error' declared with attribute 的处理 (转载)

    转自:http://blog.csdn.net/syhost/article/details/14448899 完整的报错为: system/core/include/cutils/propertie ...

  8. JS判断数组是否包含某元素

    我在学习ES6数组拓展时,发现了新增了不少了有趣的数组方法,突然想好工作中判断数组是否包含某个元素是非常常见的操作,那么这篇文章顺便做个整理. 1.for循环结合break 可能很多人第一会想到for ...

  9. 详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统)、模糊查询

    详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统).模糊查询 1,创建数据库,我的用户名:root 密码:root,数据库名称:lianwei,表名:login 2,效果 ...

  10. python自动化测试学习笔记-4常用模块

    常用模块 1.os 2.sys 3.random 4.string 5.time 6.hashlib 一.os模块 os模块主要用来操作文件.目录,与操作系统无关.要使用os模块首先要导入OS模块,用 ...