登录后抓取,然后单击按钮

时间:2016-11-23 01:16:48

标签: javascript python selenium selenium-webdriver request

我正在尝试使用selenium搜索网站,并且需要登录,然后您必须点击您的个人资料。

我已经想到了,但我似乎无法抓取页面上的数据。这是我尝试过的和我的代码:

driver = webdriver.Chrome("/Users/kingpey/Desktop/chromedriver")
site = driver.get("site")
ID = driver.find_element_by_id("username").send_keys("usernameee")
Password = driver.find_element_by_id("Password").send_keys("pass")
button = driver.find_element_by_xpath("/html/body/div[@id='page']/div[@id='main']/div[1]/form[@id='loginform']/div[@id='login']/div[@class='widgetbdy']/table[@class='txtin3']/tbody/tr[5]/td/input[@id='LoginButton']")
button.click()
time.sleep(1)
arrow = driver.find_element_by_xpath("/html/body/div[@id='page']/div[@id='main']/div[1]/div[@id='StudentBanner']/table[@id='stuBannerContainerTable']/tbody/tr/td/table[@id='stuBannerTable']/tbody/tr[@id='id']/td[3]")
arrow.click()
time.sleep(5)

箭头是我必须单击才能进入主页面的按钮。

以上所有内容都可以。现在我该如何抓住这个:

<td align="center" valign="top" class="xh-highlight">I NEED THIS</td>

我想在上面的代码中得到“我需要这个”。该页面中有许多这样的页面,我希望得到所有这些内容。

1 个答案:

答案 0 :(得分:0)

element.Text

final PopupWindow popup = new PopupWindow(); View layout = getLayoutInflater(savedInstanceState).inflate(R.layout.popup_layout, null); try { final Button b1 = (Button) layout.findViewById(R.id.cancel_action); final Button b2 = (Button) layout.findViewById(R.id.quantity_action); final Button b3 = (Button) layout.findViewById(R.id.link_action); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { paymentoptionedt.setText("Cash"); Toast.makeText(getContext(),"Cash",Toast.LENGTH_SHORT).show(); popup.dismiss(); } }); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { paymentoptionedt.setText("Card"); Toast.makeText(getContext(),"Card",Toast.LENGTH_SHORT).show(); popup.dismiss(); } }); b3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { paymentoptionedt.setText("Link Pay"); Toast.makeText(getContext(),"Link Pay",Toast.LENGTH_SHORT).show(); popup.dismiss(); } }); }catch (Exception e){ e.printStackTrace(); } popup.setContentView(layout); popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); popup.setOutsideTouchable(true); popup.setFocusable(true); popup.setBackgroundDrawable(new BitmapDrawable()); popup.showAsDropDown(view); 将返回此元素的innerText,例如。 &#34;我需要这个&#34;。