python网络爬虫(代码片段)

author author     2022-12-26     698

关键词:

# ontology_com
# Created by JKChang
# 11/06/2018, 12:46
# Tag:
# Description: extract list of ontologies from the OLS

import requests
from bs4 import BeautifulSoup

url = 'https://www.ebi.ac.uk/ols/ontologies'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')

tbody = soup.findAll('tbody')
ontos = tbody[0].findAll('tr')


class Ontology(object):
    def __init__(self, name, fullname, url, description):
        self.name = name
        self.fullname = fullname
        self.url = url
        self.description = description


res = []

for onto in ontos:
    # full name
    try:
        name = onto.findAll('a')[0].text
    except:
        name = onto.findAll('span')[0].text

    # abbreviation
    abb = onto.findAll('span', "class": "ontology-source")[0].text

    # url
    path = 'https://www.ebi.ac.uk/'
    try:
        url = onto.findAll('a')[0].attrs['href']
    except:
        url = ''

    # description
    des = onto.findAll('td')[2].text

    a = Ontology(name=abb, fullname=name, url=url, description=des)
    res.append(a)

meta = []
with open('./Desktop/ols.csv')as f:
    lines = f.readlines()
    for line in lines:
        meta.append(line.strip())

ols = []
for onto in res:
    ols.append(onto.name)


def intersection(lst1, lst2):
    return list(set(lst1) & set(lst2))


print(sorted(intersection(ols, meta)))
# Created by JKChang
# 08/08/2017, 12:26
# Tag:
# Description: films hyperlink exraction
 
import re
import urllib.request
 
url = 'http://videos.yizhansou.com/5004'
fp = urllib.request.urlopen(url)
mybytes = fp.read()
 
mystr = mybytes.decode('gbk').strip()
fp.close()
 
links = re.findall(r"(?<=href=\").+?(?=\")|(?<=href=\').+?(?=\')", mystr)
 
for link in links:
    if link.__contains__('ed2k'):
        print(link)
import urllib.request


from bs4 import BeautifulSoup

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.PhantomJS()
driver.get(r"https://bioportal.bioontology.org/ontologies")

wait = WebDriverWait(driver, 10)

# click proceed
proceed = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Proceed")))
proceed.click()

# wait for the content to be present
wait.until(EC.presence_of_element_located((By.ID, "workskin")))

soup = BeautifulSoup(driver.page_source, "html.parser")


with open('res.txt','w') as f:
    f.write(soup)

python教程入门学习python爬虫入门学习:网络爬虫是什么(代码片段)

网络爬虫又称网络蜘蛛、网络机器人,它是一种按照一定的规则自动浏览、检索网页信息的程序或者脚本。网络爬虫能够自动请求网页,并将所需要的数据抓取下来。通过对抓取的数据进行处理,从而提取出有价值的... 查看详情

python爬虫一个简单的网络爬虫(代码片段)

网页结构的相似性爬虫的目的,是从网站中 自动化 的 批量 提取数据。首先尝试完成以下操作:从以下链接中提取电影的标题和标题后的年份:https://movie.douban.com/subject/1292052/https://movie.douban.com/subject/1962665/https://movi... 查看详情

网络爬虫是什么?怎么学python爬虫(代码片段)

网络爬虫又称网络蜘蛛、网络机器人,它是一种按照一定的规则自动浏览、检索网页信息的程序或者脚本。网络爬虫能够自动请求网页,并将所需要的数据抓取下来。通过对抓取的数据进行处理,从而提取出有价值的... 查看详情

python网络爬虫之scrapy框架(crawlspider)(代码片段)

目录Python网络爬虫之Scrapy框架(CrawlSpider)CrawlSpider使用爬取糗事百科糗图板块的所有页码数据Python网络爬虫之Scrapy框架(CrawlSpider)提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法?方法一... 查看详情

python项目实战之网络爬虫详解(代码片段)

文章目录一、概述二、原理三、爬虫分类1、传统爬虫2、聚焦爬虫3、通用网络爬虫(全网爬虫)四、网页抓取策略1、宽度优先搜索:2、深度优先搜索:3、最佳优先搜索:4、反向链接数策略:5、PartialPageRa... 查看详情

python爬虫从入门到放弃,网络爬虫应用实战(代码片段)

python爬虫应用Request库get方法Request对象Response对象session会话对象正则匹配re.match()方法例题:bugku-web基础$_POST例题:bugku-速度要快例题:bugku-秋名山老司机例题:bugku-cookies欺骗Request库get方法Pythonrequests库的get()方法... 查看详情

python爬虫从入门到放弃,网络爬虫应用实战(代码片段)

python爬虫应用Request库get方法Request对象Response对象session会话对象正则匹配re.match()方法例题:bugku-web基础$_POST例题:bugku-速度要快例题:bugku-秋名山老司机例题:bugku-cookies欺骗Request库get方法Pythonrequests库的get()方法... 查看详情

python网络异步爬虫(aiohttp库)(代码片段)

0x01单线程访问网页importrequestsimporttimenum=20url="https://www.dandanzan10.top/dianying/index.html"ks=time.time()for_inrange(1,num+1):res=requests.get(url)print(res.text[:10])js 查看详情

python网络异步爬虫(aiohttp库)(代码片段)

0x01单线程访问网页importrequestsimporttimenum=20url="https://www.dandanzan10.top/dianying/index.html"ks=time.time()for_inrange(1,num+1):res=requests.get(url)print(res.text[:10])js 查看详情

python爬虫编程思想:实战案例:抓取所有的网络资源(代码片段)

       Python爬虫编程思想(7):实战案例:抓取博客文章列表         到现在为止,我们已经对网络爬虫涉及到的基本知识有了一个初步的了解。本文会编写一个简单的爬虫应用,以便让读者对爬... 查看详情

网络爬虫(代码片段)

1.爬虫流程图2.简单爬虫整个网页的内容--python2importurllib2response=urllib2.urlopen("http://www.baidu.com")html=response.read()print(html) 3.中文乱码处理 #coding:utf-8importre#importrequestsimportsysimportcodecs#p 查看详情

python——网络爬虫,一个简单的通用代码框架(代码片段)

一、代码"""通用代码框架:可使网页爬取变得更稳定更有效下面是一个爬取百度网页的例子,正常情况下是返回"""importrequestsdefget_HTML_Text():try:r=requests.get(url,timeout=30)r.raise_for_status()#若状态不是200,引发HTTPError异常r.encoding=r.apparen... 查看详情

python爬虫编程思想(14):网络爬虫中的异常处理(代码片段)

       目录1.URLError2.HTTPError         在前面的文章中详细讲解了发送请求的过程,但这是在正常情况下的使用。如果非正常使用,例如,提供的URL根本就是错的,那么在发... 查看详情

python网络爬虫与信息提取—requests库入门(代码片段)

...c;自动网络请求提交此博客为中国大学MOOC北京理工大学《Python网络爬虫与信息提取》的学习笔记requests库的安装requests库是Python的第三方库,是目前公认的,爬取网页最好的第三方库。关于requests库的更多信息,可以在... 查看详情

python爬虫|网络爬虫简介(代码片段)

文章目录Python爬虫|网络爬虫简介网络爬虫何时有用网络爬虫是否合法背景调研检查robots.txt检查网站地图估算网站大小识别网站所用技术寻找网站所有者编写第一个网络爬虫下载网页网站地图爬虫ID遍历爬虫链接爬虫Python爬虫|网... 查看详情

python爬虫|网络爬虫简介(代码片段)

文章目录Python爬虫|网络爬虫简介网络爬虫何时有用网络爬虫是否合法背景调研检查robots.txt检查网站地图估算网站大小识别网站所用技术寻找网站所有者编写第一个网络爬虫下载网页网站地图爬虫ID遍历爬虫链接爬虫Python爬虫|网... 查看详情

python网络爬虫:伪装浏览器(代码片段)

添加超时跳过功能首先,我简单地将urlop=urllib.request.urlopen(url)改为urlop=urllib.request.urlopen(url,timeout=2)运行后发现,当发生超时,程序因为exception中断.于是我把这一句也放在try..except结构里,问题解决.支持自动跳转在爬http://baidu... 查看详情

python网络爬虫:伪装浏览器(代码片段)

添加超时跳过功能首先,我简单地将urlop=urllib.request.urlopen(url)改为urlop=urllib.request.urlopen(url,timeout=2)运行后发现,当发生超时,程序因为exception中断.于是我把这一句也放在try..except结构里,问题解决.支持自动跳转在爬http://baidu... 查看详情