Sign in

XPath crawls the number of fans, and the returned value is empty?

pg7733 edited in Wed, 23 Nov 2022


Crawl the number of fans in the microblog user's home page, as shown in the figure:


from lxml import etreeimport requestsurl = ' https://weibo.com/n/ Phoenix video '

Headers = {cookie ':','user agent ':'} / / it's too long. Delete the specific content

response = requests.get (url,headers=headers)html = response.contentdata = etree.HTML (html).xpath('//*[@id="Pl_ Core_ T8CustomTriColumn__ 3"]/div/div/div/table/tr/td[2]/a/strong/text()')print(data)

屏幕快照 2020-02-01 上午11.27.17.png

What is the actual error message you see?

The returned data is null. Remove the tbody in XPath, it's still empty

Hope to get answers! thank you????

1 Replies
commented on Wed, 23 Nov 2022

The content is loaded dynamically. What you see in this way is the result of JS execution, so you can't get it. You should directly look at the source code of the page- source:https :// weibo.com/ifengvideo?... , Then get the corresponding content.