Giter Site home page Giter Site logo

sfvsfv / crawer Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 7.0 44.56 MB

《Python网络爬虫入门到实战》配套程序。爬虫项目集合,

Home Page: https://item.jd.com/14049708.html

License: MIT License

HTML 5.25% CSS 0.01% Jupyter Notebook 93.51% Python 1.23%
lxml pymysql python3 scrapy selenium urllib xpath

crawer's Introduction



😆 Hey! Welcome to my profile

🍉 Take a look at my stats 🌱

wangyang0210's github stats


javascript typescript react nodejs vue electron php docker

crawer's People

Contributors

sfvsfv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

crawer's Issues

p92 段子爬取,第一页正则匹配好像没完全匹配上,只匹配到了17个,但是菜鸟工具看正则匹配到了20个

https://xiaohua.zol.com.cn/baoxiaonannv/1.html

运行代码

# 导入模块
import logging

# 匹配内容
import re

# 网页请求
import requests

# 忽略警告
logging.captureWarnings(True)
# 控制时间
import time

# 写入请求网址与请求头
url = "https://xiaohua.zol.com.cn/baoxiaonannv/%d.html"
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
}


# 正则表达式
pattern = re.compile(r'<div class="summary-text">(.*?)</div>')


duanzi = url % (1)
print(duanzi)
requests.packages.urllib3.disable_warnings()
# 获取代码内容,cerify=False不认证
response = requests.get(url=duanzi, headers=header, verify=False, timeout=10).text
# 正则匹配
item = pattern.findall(response, re.S)
time.sleep(2)

response
# print(item)

image

通过正则表达式<div class="summary-text">(.*?)</div>照理来说应该这20个都匹配到了,但是为什么这3个没有匹配到?re.S似乎能含\n但是没有制表符\t。是这个问题吗?那正则表达式该怎么改使得\t也能被匹配
image
image

image
image

image

P79页,正则表达式特殊字符贪婪模式与非贪婪模式表达有误

image

在贪婪模式下,匹配器尽可能多地匹配符合要求的字符,直到不能再匹配为止。例如,正则表达式 a.*b 在匹配字符串 "abbcab" 时,会匹配整个字符串 "abbcab",而不是期望的 "ab"。

在非贪婪模式下,匹配器尽可能少地匹配符合要求的字符,直到满足要求为止。例如,正则表达式 a.*?b 在匹配字符串 "abbcab" 时,只会匹配到第一个 "ab",而不是整个字符串。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.