我想在bs4中获取表格的高度和宽度。我没有在html中为表格分配任何高度和宽度,我希望表格的高度和宽度应该是动态的,有没有办法在bs4中动态访问高度和宽度?
public void ShowData()//String data)
{
final ProgressDialog progressDialog =new ProgressDialog ( this );
progressDialog.setMessage ( "Loading.." );
progressDialog.show ();
query1 = myRef.orderByChild ( "dateTime" ); // this is for Filter the data (The recently data you add is show on top of application)
// options=new FirebaseRecyclerOptions.Builder<modelClass> ().setQuery ( myRef,modelClass.class ).build ();//for retrive
options = new FirebaseRecyclerOptions.Builder < modelClass > ().setQuery ( query1 , modelClass.class ).build ();//for search and retrive
adapter = new FirebaseRecyclerAdapter < modelClass, MyVIewHolder > ( options ) {
@Override
protected void onBindViewHolder(@NonNull final MyVIewHolder holder , final int position , @NonNull modelClass model) //for binding the View of recycler_view_item_layout
{
/* holder.college.setText ( model.getCollege () );
holder.contact.setText ( model.getContact () );
holder.time.setText ( model.getDateTime ());
holder.food.setText ( model.getFood () );
holder.name.setText ( model.getName () );*/
progressDialog.dismiss ();
holder.setFoodPost ( model ); //for set all data to view
//for set intent on Contact num View
holder.contact.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View view) {
String phoneNum = holder.contact.getText ().toString ();
Intent in = new Intent ( Intent.ACTION_DIAL );
in.setData ( Uri.parse ( "tel:" + phoneNum ) ); // This ensures only Dial apps respond
if (in.resolveActivity ( getPackageManager () ) != null) {
startActivity ( in );
} else {
Toast.makeText ( MainActivity.this , "Failed" , Toast.LENGTH_SHORT ).show ();
}
}
} );
//for longPress on particular view(CardView)
//for Delete the particular data when press long click on the View(CardView)
holder.itemView.setOnLongClickListener ( new View.OnLongClickListener () {
@Override
public boolean onLongClick(View view) {
//for post_key we simply fetch that data postion which we want to delete
post_key = getRef ( position ).getKey ();
openDeleteWindow ();//this is a method for open the Delete Window
// Toast.makeText ( MainActivity.this , "Press" , Toast.LENGTH_SHORT ).show ();
return true;
}
} );
当我打印html = fancy_html(i)
soup = BeautifulSoup(html)
mydivs = soup.findAll("table")
时,将获得带有值的表格。 我想访问它们的高度和宽度,我不想固定桌子的高度和宽度
答案 0 :(得分:0)
如果您有类似以下内容的html,则可以尝试以下代码
# main.py
from bs4 import BeautifulSoup as bs
html_content = """
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>Harry</td>
<td>Willson</td>
<td>34</td>
</tr>
<tr>
<td>Tom</td>
<td>Harison</td>
<td>65</td>
</tr>
</table>
"""
soup = bs(html_content, "html.parser")
tr = soup.findAll("tr")
th = soup.findAll("th")
height = len(tr)
width = len(th)
print("height:", height)
print("width:", width)
~$ python3 main.py
高度:5
宽度:3