python爬取微博用户ID问题

环环jiayou 2016-07-26 04:31:53
 identity = driver.find_elements_by_xpath("//a[@class='W_texta W_fb']")

这个代码得到微博ID的所在位置,内容如下所示:

然后我要怎么写才能提出这个用户的ID呢?该用户的ID是09zoey,即http://weibo.com/后面的部分,问号前面的部分呢?
...全文
515 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
环环jiayou 2016-07-27
  • 打赏
  • 举报
回复
显示的是nick-name的内容,identity打印出来是空的[/quote] 这帮不了你了试试identity[1],identity[2]之类的,看官方API[/quote] 根据[code=pythonidentity = driver.find_elements_by_xpath("//a[@class='W_texta W_fb']")][/code]这个类,我可以把后面的href,也就是http://weibo.com/u/5133308512拿出来吗?
环环jiayou 2016-07-27
  • 打赏
  • 举报
回复
引用 8 楼 a87b01c14 的回复:
[quote=引用 7 楼 u010735814 的回复:] [quote=引用 6 楼 a87b01c14 的回复:] [quote=引用 5 楼 u010735814 的回复:] [quote=引用 4 楼 a87b01c14 的回复:] 后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢? [/quote] 什么意思?identity[0].text 你还不知道是什么内容?[/quote] 显示的是nick-name的内容,identity打印出来是空的[/quote] 这帮不了你了试试identity[1],identity[2]之类的,看官方API[/quote]
引用 8 楼 a87b01c14 的回复:
[quote=引用 7 楼 u010735814 的回复:] [quote=引用 6 楼 a87b01c14 的回复:] [quote=引用 5 楼 u010735814 的回复:] [quote=引用 4 楼 a87b01c14 的回复:] 后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢? [/quote] 什么意思?identity[0].text 你还不知道是什么内容?[/quote] 显示的是nick-name的内容,identity打印出来是空的[/quote] 这帮不了你了试试identity[1],identity[2]之类的,看官方API[/quote] identity显示是个list,identity打印出来是空的
sanxiaochengyu 2016-07-27
  • 打赏
  • 举报
回复
引用 7 楼 u010735814 的回复:
[quote=引用 6 楼 a87b01c14 的回复:] [quote=引用 5 楼 u010735814 的回复:] [quote=引用 4 楼 a87b01c14 的回复:] 后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢? [/quote] 什么意思?identity[0].text 你还不知道是什么内容?[/quote] 显示的是nick-name的内容,identity打印出来是空的[/quote] 这帮不了你了试试identity[1],identity[2]之类的,看官方API
环环jiayou 2016-07-27
  • 打赏
  • 举报
回复
引用 6 楼 a87b01c14 的回复:
[quote=引用 5 楼 u010735814 的回复:] [quote=引用 4 楼 a87b01c14 的回复:] 后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢? [/quote] 什么意思?identity[0].text 你还不知道是什么内容?[/quote] 显示的是nick-name的内容,identity打印出来是空的
sanxiaochengyu 2016-07-27
  • 打赏
  • 举报
回复
引用 5 楼 u010735814 的回复:
[quote=引用 4 楼 a87b01c14 的回复:] 后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢? [/quote] 什么意思?identity[0].text 你还不知道是什么内容?
环环jiayou 2016-07-26
  • 打赏
  • 举报
回复
引用 4 楼 a87b01c14 的回复:
后面这个字符串打印一下,是什么
这个identity是driver.find_elements_by_xpath("//a[@class='W_texta W_fb']"),从微博来看,它包含图片里面的内容,可是我要怎样才能提取出来呢?
sanxiaochengyu 2016-07-26
  • 打赏
  • 举报
回复
后面这个字符串打印一下,是什么
环环jiayou 2016-07-26
  • 打赏
  • 举报
回复
引用 1 楼 a87b01c14 的回复:

import re

string = "aaaaaaaaaaahttp://weibo.com/abcde?bbbbbbbbbbbbbb"
pattern = re.compile("http://weibo.com/(.*?)\?")
items = re.findall(pattern, string)
print(items)

 identity = driver.find_elements_by_xpath("//a[@class='W_texta W_fb']")
        pattern = re.compile("http://weibo.com/(.*?)\?")
        items = re.findall(pattern, identity[0].text)
        print items
如果是这样写是正确的吗?但是这样输不出任何东西
ficuszhu 2016-07-26
  • 打赏
  • 举报
回复
各位大神,有想找python新机会的吗
sanxiaochengyu 2016-07-26
  • 打赏
  • 举报
回复

import re

string = "aaaaaaaaaaahttp://weibo.com/abcde?bbbbbbbbbbbbbb"
pattern = re.compile("http://weibo.com/(.*?)\?")
items = re.findall(pattern, string)
print(items)

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧