|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
背景:win10系统,python3.5
最近在爬知乎的数据,遇到一个网站里面含有json数据(代码如下)。我在爬下来网页信息后,想通过正则的方式来找到需要的信息,正则表达式为data-state='(.*?)',这个表达式在网上测试后是可以找到data-state里面的信息的。但是我在python中输入的时候,却一直找不到(见下图),就是这个问题,请大神指点一下。万分感谢/(ㄒoㄒ)/~~
- <div data-config='{"apiAddress":"/api/v4/","deployEnv":"production"}' data-reactid="19" data-state='{"loading":{"global":{"count":0},"local":{"token/":false,"env/getExperiments/":false,"config/getAppConfig/":false,"people/get/":false,"people/getActivities/yuxinlie\n":false}},"entities":{"users":{"yuxinlie":{"isFollowed":false,"educations":[],"followingCount":732,"voteFromCount":0,"userType":"people","showSinaWeibo":false,"pinsCount":681,"isFollowing":false,"markedAnswersText":"知乎圆桌和编辑推荐","isPrivacyProtected":false,"accountStatus":[],"isForceRenamed":false,"id":"246e6cf44e94cefbf4b959cb5042bc91","favoriteCount":2,"voteupCount":27271,"commercialQuestionCount":0,"isBlocking":false,"followingColumnsCount":112,"headline":"和自己赛跑","urlToken":"yuxinlie","participatedLiveCount":268,"followingFavlistsCount":12,"isAdvertiser":false,"isBindSina":true,"favoritedCount":7163,"isOrg":false,"followerCount":161166,"employments":[],"type":"people","avatarHue":"","avatarUrlTemplate":"https://pic4.zhimg.com/3d4085b43_{size}.jpg","followingTopicCount":224,"description":"家住西城区的于先生","avatarUrl":"https://pic4.zhimg.com/3d4085b43_is.jpg","columnsCount":3,"hostedLiveCount":5,"isActive":1,"thankToCount":0,"mutualFolloweesCount":0,"markedAnswersCount":13,"coverUrl":"https://pic2.zhimg.com/v2-3aeb700c73536cd84bd1dd40f660c365_b.jpg","thankFromCount":0,"voteToCount":0,"isBlocked":false,"answerCount":409,"allowMessage":false,"articlesCount":168,"name":"于欣烈","questionCount":212,"locations":[{"introduction":"","avatarUrl":"https://pic1.zhimg.com/e82bab09c_is.jpg","name":"列支敦士登","url":"http://www.zhihu.com/api/v4/topics/19886373","type":"topic","excerpt":"","id":"19886373"}],"badge":[{"topics":[{"introduction":"电动汽车(Electric Car)泛指所有使用电能驱动电动机在道路上行驶的车辆(Automobile)。而不能脱离供电接触网的单电源无轨电车和在电气化铁路路轨上行驶的铁路列车,并不包括在内。 电动汽车电能的来源有很多种,例如由太阳能板供电的太阳能车,由电池供电的纯电动车。","avatarUrl":"https://pic1.zhimg.com/ec41b076c_is.jpg","name":"电动汽车","url":"http://www.zhihu.com/api/v4/topics/19561561","type":"topic","excerpt":"电动汽车(Electric Car)泛指所有使用电能驱动电动机在道路上行驶的车辆(Automobile)。而不能脱离供电接触网的单电源无轨电车和在电气化铁路路轨上行驶的铁路列车,并不包括在内。 电动汽车电能的来源有很多种,例如由太阳能板供电的太阳能车,由电池供电的纯电动车。","id":"19561561"}],"type":"best_answerer","description":"优秀回答者"}],"url":"http://www.zhihu.com/api/v4/people/246e6cf44e94cefbf4b959cb5042bc91","messageThreadToken":"0513324000","logsCount":889,"followingQuestionCount":2033,"thankedCount":2157,"gender":1}},"questions":{},"answers":{},"articles":{},"columns":{},"topics":{},"roundtables":{},"favlists":{},"comments":{},"notifications":{},"ebooks":{},"activities":{"undefined":{"0":{"type":"best_answerer","description":"优秀回答者"}}},"feeds":{},"pins":{},"promotions":{}},"currentUser":"","token":{"xsrf":"d988f6dd72f2c9a6b54ce97912142400","xUDID":"AGACjfTWCQyPTuyFGC_I5X5LoymJMXqZdgo="},"account":{"locakTicketStatus":false,"challenge":[],"errorStatus":false,"message":"","isFetching":false},"notification":{},"people":{"isFetching":false,"activitiesByUser":{"yuxinlie\n":{"isFetching":false,"ids":["https://pic4.zhimg.com/3d4085b43_{size}.jpg","people","于欣烈","和自己赛跑","people",false,"https://pic4.zhimg.com/3d4085b43_is.jpg",false,1,"http://www.zhihu.com/api/v4/people/246e6cf44e94cefbf4b959cb5042bc91","yuxinlie","246e6cf44e94cefbf4b959cb5042bc91"],"newIds":["https://pic4.zhimg.com/3d4085b43_{size}.jpg","people","于欣烈","和自己赛跑","people",false,"https://pic4.zhimg.com/3d4085b43_is.jpg",false,1,"http://www.zhihu.com/api/v4/people/246e6cf44e94cefbf4b959cb5042bc91","yuxinlie","246e6cf44e94cefbf4b959cb5042bc91"]}},"answersByUser":{},"answersSortByVotesByUser":{},"answersMarkedByUser":{},"votedAnswersByUser":{},"thankedAnswersByUser":{},"voteAnswersByUser":{},"thankAnswersByUser":{},"topicAnswersByUser":{},"articlesByUser":{},"articlesSortByVotesByUser":{},"pinsByUser":{},"questionsByUser":{},"commercialQuestionsByUser":{},"favlistsByUser":{},"followingByUser":{},"followersByUser":{},"mutualsByUser":{},"followingColumnsByUser":{},"followingQuestionsByUser":{},"followingFavlistsByUser":{},"followingTopicsByUser":{},"publicationsByUser":{},"columnsByUser":{},"allFavlistsByUser":{},"brands":null},"env":{"experiment":{"ge3":"ge3_9","ge2":"ge2_1","nwebStickySidebar":"sticky","newMore":"new","liveReviewBuyBar":"live_review_buy_bar_2","liveStore":"ls_a1_b2_c1_f1","isOffice":"false","homeUi2":"default","answerRelatedReadings":"qa_recommend_with_ads_and_article","remixOneKeyPlayButton":"headerButton","qrcodeLogin":"qrcode","newBuyBar":"livenewbuy3","isShowUnicomFreeEntry":"unicom_free_entry_off","newMobileColumnAppheader":"old_header","zcmLighting":"zcm","favAct":"default","appStoreRateDialog":"close","mobileQaPageProxyHeifetz":"m_qa_page_nweb","iOSNewestVersion":"4.2.0","default":"None","wechatShareModal":"wechat_share_modal_show","qaStickySidebar":"sticky_sidebar","androidProfilePanel":"panel_a","nwebWriteAnswer":"experiment"},"userAgent":{"Edge":false,"Wechat":false,"Weibo":false,"QQ":false,"Mobile":false,"Android":false,"iOS":false,"isAppleDevice":false,"Zhihu":false,"ZhihuHybrid":false,"isBot":false,"isWebView":false},"trafficSource":"","edition":{"baidu":false,"yidianzixun":false},"theme":"light","referer":"https://www.zhihu.com/topic/19559424/followers","conf":{"unblockContacts":{"telecom":"1069 0920 21212","mobile":"1069 02098 21212","unicom":"1069 0920 21212"}}},"config":{"isWindow":1,"canWrite":false,"alertTimeSpan":3600,"tip":"应国家法规对于帐号实名的要求,进行下一步操作前,需要先完成手机绑定。"},"pushNotifications":{"default":{"isFetching":false,"isDrained":false,"ids":[]},"follow":{"isFetching":false,"isDrained":false,"ids":[]},"vote-thank":{"isFetching":false,"isDrained":false,"ids":[]},"currentTab":"default","notificationsCount":{"default":0,"follow":0,"vote-thank":0}},"messages":{"data":{},"currentTab":"common","messageCount":0},"register":{"registerValidateSucceeded":null,"registerValidateErrors":{},"registerConfirmError":null,"sendDigitsError":null,"registerConfirmSucceeded":null},"login":{"loginUnregisteredError":false,"loginBindWechatError":false,"loginConfirmError":null,"sendDigitsError":null,"validateDigitsError":false,"loginConfirmSucceeded":null,"qrcodeLoginToken":"","qrcodeLoginScanStatus":0,"qrcodeLoginError":null,"qrcodeLoginReturnNewToken":false},"active":{"sendDigitsError":null,"activeConfirmSucceeded":null,"activeConfirmError":null},"question":{"followers":{},"concernedFollowers":{},"answers":{},"hiddenAnswers":{},"createdAnswers":{},"collapsedAnswers":{},"notificationAnswers":{},"invitationCandidates":{},"inviters":{},"invitees":{},"similarQuestions":{},"relatedLives":{},"recommendReadings":{},"bio":{},"brand":{},"commonAnswerCount":0,"hiddenAnswerCount":0},"comments":{"pagination":{},"collapsed":{},"reverse":{},"reviewing":{},"conversation":{},"parent":{}},"shareTexts":{},"answers":{"voters":{},"copyrightApplicants":{},"favlists":{},"newAnswer":{}},"banner":{},"topics":{"bios":{}},"captcha":{"captchaNeeded":false,"captchaValidated":false,"captchaBase64String":null,"captchaValidationMessage":null,"loginCaptchaExpires":false},"sms":{"supportedCountries":[]},"explore":{"recommendations":{},"hotfeeds":{}},"articles":{"voters":{}},"favlists":{"relations":{}},"pins":{"voters":{}},"topstory":{"topstorys":{"isFetching":false,"isDrained":false,"afterId":0,"items":[],"next":null},"sidebar":null,"announcement":{}},"upload":{},"video":{"data":{}},"guide":{"guide":{"isFetching":false,"isShowGuide":false}},"switches":{},"coupon":{"isRedeemingCoupon":false},"reward":{},"search":{"recommendSearch":[],"topSearch":{},"generalByQuery":{},"peopleByQuery":{},"topicByQuery":{},"columnByQuery":{},"liveByQuery":{},"eBookByQuery":{}},"org":{"resume":{}}}' id="data" style="display:none;">
- </div>
复制代码
是不是 a 不是你贴出的那个字符串?是其他字符串甚至其他类型?
我试了下,是成功了的。你 print (a) 看看。
|
-
列表为空
|