Python crawlers need to extract the & lt; span & gt; AppleiPhone5s (A1530) 16 GB golden mobile Unicom 4G mobile phone & lt; span & gt; here, the phone name cannot match exactly because it is used in beginners. * Only AppleiPhone5s can be matched. (A1, please give me some advice! Has been sleepy python crawler, need to extract html Apple iPhone 5S (A1530) 16 GB gold mobile Unicom 4G mobile phone here on the phone name, because beginners can not match completely, which is used. * Can only match the Apple iPhone 5S (A1 please give pointers! It has been stuck for two days! Reply content: Thank you for your invitation.
I 've come to amway xpath again. Give up the regular expression.
//span[@class="pro-title"]/text()
No one uses BeautifulSoup?
(? <=> ).*? (? = <)
If there are many different "<>" pairs in the actual situation, please fill in the content of the forward and backward assertions by yourself. You should check the Chinese character encoding. The webpage code is probably GBK, however, python uses utf8, so it cannot be matched.
I am so sad to see that I am not familiar with regular expressions !!
--------------- Code zone -------------- # coding: utf-8import rex = 'apple iPhone 5S (A1530) 16 GB gold mobile Unicom 4G mobile phone 'xre = R '()(. +) () 'z = re. search (xre, x ). group (2) print z ---------- output zone ----------------------- C: \ Python27 \ python.exe D:/PycharmProjects/crawler/test. pyApple iPhone 5S (A1530) 16 GB gold mobile Unicom 4G mobile phone process has ended, exit code 0
. +/SSU can usually match Chinese in this way,
Find the node by using the prefix or regular expression, and then match it with the character group above.
Assume that there is only one node. The usage is as follows:
import reimport requests as reqfrom bs4 import BeautifulSoupurl = 'xxx'html = req.get(url).textbs = BeautifulSoup(html)span = bs.find_all('span', 'pro-title')'''span = re.findall('[^<]+', html)s = span[0]m = re.findall('[\u4e00-\u9fa5]+', s)'''s = str(span)m = re.findall('[\u4e00-\u9fa5]+', s)print(m)
If pyquery uses jquery, you will fall in love with it and use phpQuery in php.
CSS Selector